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

Output binary columns in "sqlite-utils query" JSON #125

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

Output binary columns in "sqlite-utils query" JSON #125

simonw opened this issue Jul 26, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Jul 26, 2020

You get an error if you try to run a query that returns data from a BLOB.

@simonw simonw added the bug Something isn't working label Jul 26, 2020
@simonw
Copy link
Owner Author

simonw commented Jul 26, 2020

Best solution I can think of is to return the data as base64. It's a bit nasty since it means you can't round trip it back again.

@simonw
Copy link
Owner Author

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.

@simonw
Copy link
Owner Author

simonw commented Jul 27, 2020

I'm going to imitate how Datasette solves this problem:

[
  {
    "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"
    }
  }
]

@simonw simonw changed the title sqlite-utils query JSON breaks for binary columns Output binary columns in JSON Jul 27, 2020
@simonw simonw changed the title Output binary columns in JSON Output binary columns in "sqlite-utils query" JSON Jul 27, 2020
@simonw simonw closed this as completed in 20e543e Jul 27, 2020
@simonw
Copy link
Owner Author

simonw commented Jul 27, 2020

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
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant