Ability to insert base64 binary data as JSON, closes #126

This commit is contained in:
Simon Willison 2020-07-26 20:59:15 -07:00
commit 1a61a6d3d6
5 changed files with 67 additions and 3 deletions

View file

@ -65,10 +65,10 @@ Binary strings are not valid JSON, so BLOB columns containing binary data will b
$ sqlite-utils dogs.db "select name, content from images" | python -mjson.tool
[
{
"name": "smile.gif",
"name": "transparent.gif",
"content": {
"$base64": true,
"encoded": "eJzt0c1x..."
"encoded": "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
}
}
]
@ -295,6 +295,18 @@ If you feed it a JSON list it will insert multiple records. For example, if ``do
}
]
You can insert binary data into a BLOB column by first encoding it using base64 and then structuring it like this::
[
{
"name": "transparent.gif",
"content": {
"$base64": true,
"encoded": "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
}
}
]
You can import all three records into an automatically created ``dogs`` table and set the ``id`` column as the primary key like so::
$ sqlite-utils insert dogs.db dogs dogs.json --pk=id