mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-25 02:34:24 +02:00
Ability to insert base64 binary data as JSON, closes #126
This commit is contained in:
parent
814d4a7f90
commit
1a61a6d3d6
5 changed files with 67 additions and 3 deletions
16
docs/cli.rst
16
docs/cli.rst
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue