mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-01 15:04:11 +02:00
sqlite-utils insert ... --nl option, closes #6
This commit is contained in:
parent
57fc8ce55e
commit
5309c5c775
3 changed files with 29 additions and 7 deletions
|
|
@ -104,13 +104,25 @@ def test_insert_multiple_with_primary_key(db_path, tmpdir):
|
|||
cli.cli, ["insert", db_path, "dogs", json_path, "--pk", "id"]
|
||||
)
|
||||
assert 0 == result.exit_code
|
||||
assert dogs == Database(db_path).execute_returning_dicts(
|
||||
"select * from dogs order by id"
|
||||
)
|
||||
db = Database(db_path)
|
||||
assert dogs == db.execute_returning_dicts("select * from dogs order by id")
|
||||
assert ["id"] == db["dogs"].pks
|
||||
|
||||
|
||||
def test_insert_newline_delimited(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["insert", db_path, "from_json_nl", "-", "--nl"],
|
||||
input='{"foo": "bar", "n": 1}\n{"foo": "baz", "n": 2}',
|
||||
)
|
||||
assert 0 == result.exit_code, result.output
|
||||
db = Database(db_path)
|
||||
assert [
|
||||
{"foo": "bar", "n": 1},
|
||||
{"foo": "baz", "n": 2},
|
||||
] == db.execute_returning_dicts("select foo, n from from_json_nl")
|
||||
|
||||
|
||||
def test_upsert(db_path, tmpdir):
|
||||
test_insert_multiple_with_primary_key(db_path, tmpdir)
|
||||
json_path = str(tmpdir / "upsert.json")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue