mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-26 02:44:33 +02:00
Store list/dict/tuple values as JSON strings
This commit is contained in:
parent
acea54877c
commit
95bce37ad3
2 changed files with 36 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from sqlite_utils import db
|
||||
import json
|
||||
import sqlite3
|
||||
import pytest
|
||||
|
||||
|
|
@ -54,3 +55,20 @@ def test_create_table_works_for_m2m_with_only_foreign_keys(fresh_db):
|
|||
{"name": "one_id", "type": "INTEGER"},
|
||||
{"name": "two_id", "type": "INTEGER"},
|
||||
] == [{"name": col.name, "type": col.type} for col in fresh_db["m2m"].columns]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data_structure",
|
||||
(
|
||||
["list with one item"],
|
||||
["list with", "two items"],
|
||||
{"dictionary": "simple"},
|
||||
{"dictionary": {"nested": "complex"}},
|
||||
[{"list": "of"}, {"two": "dicts"}],
|
||||
),
|
||||
)
|
||||
def test_insert_dictionaries_and_lists_as_json(fresh_db, data_structure):
|
||||
fresh_db["test"].insert({"id": 1, "data": data_structure}, pk="id")
|
||||
row = fresh_db.conn.execute("select id, data from test").fetchone()
|
||||
assert row[0] == 1
|
||||
assert data_structure == json.loads(row[1])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue