Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to insert binary data on the CLI using JSON #126

Closed
simonw opened this issue Jul 26, 2020 · 2 comments
Closed

Ability to insert binary data on the CLI using JSON #126

simonw opened this issue Jul 26, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jul 26, 2020

I could solve round tripping (at least a bit) by allowing insert to be run with a flag that says "these columns are base64 encoded, store the decoded data in a BLOB".

That would solve inserting binary data using JSON too.
Originally posted by @simonw in #125 (comment)

@simonw simonw added the enhancement New feature or request label Jul 27, 2020
@simonw
Copy link
Owner Author

simonw commented Jul 27, 2020

I'm going to implement this as the reverse of #125 - binary columns in JSON are now output like this:

  {
    "name": "lorem.txt",
    "mode": 33188,
    "mtime": 1595805965,
    "sz": 16984,
    "data": {
      "$base64": true,
      "encoded": "eJzt0c1xAyEMBeC7q1ABHleR3HxNAQrIjmb4M0gelx+RTY7p4N2WBYT0vmufUknH8kq5lz5pqRFXsTOl3pYkE/NJnHXoStruJEVjc0mOCyTqq/ZMJnXEZW1Js2ZvRm5U+DPKk9hRWqjyvTFx0YfzhT6MpGmN2lR1fzxjyfVMD9dFrS+bnkleMpMam/ZGXgrX1I/K+5Au3S/9lNQRh0k4Gq/RUz8GiKfsQm+7JLsJ6fTo5JhVG00ZU76kZZkxePx49uIjnpNoJyYlWUsoaSl/CcVATje/Kxu13RANnrHweaH3V5Jh4jvGyKCnxJLiXPKhmW3fiCnG7Jql7RR3UvFo8jJ4z039dtOkTFmWzL1be9lt8A5II471m6vXy+l0BR/4wAc+8IEPfOADH/jABz7wgQ984AMf+MAHPvCBD3zgAx/4wAc+8IEPfOADH/jABz7wgQ984AMf+MAHPvCBD3zgAx/4wAc+8IEPfOADH/jABz7wgQ984PuP7xubBoN9"
    }
  }
]

So the sqlite-utils insert command should learn to spot {"$base64": true...} values and base64 decode them before inserting them.

@simonw simonw closed this as completed in 1a61a6d Jul 27, 2020
@simonw
Copy link
Owner Author

simonw commented Jul 27, 2020

$ echo '[
    {
        "name": "transparent.gif",
        "content": {
            "$base64": true,
            "encoded": "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
        }
    }
]' | sqlite-utils insert trans.db files - --pk=name

simonw added a commit that referenced this issue Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant