mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Handle db.table(table_name).insert({}), closes #759
This commit is contained in:
parent
401fb6949c
commit
b5d0080cd1
2 changed files with 40 additions and 1 deletions
|
|
@ -31,3 +31,24 @@ def test_quote_default_value(fresh_db, column_def, initial_value, expected_value
|
|||
assert expected_value == fresh_db.quote_default_value(
|
||||
fresh_db["foo"].columns[0].default_value
|
||||
)
|
||||
|
||||
|
||||
def test_insert_empty_record_uses_default_values(fresh_db):
|
||||
fresh_db.execute("""
|
||||
CREATE TABLE has_defaults (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
is_active INTEGER NOT NULL DEFAULT 1
|
||||
)
|
||||
""")
|
||||
|
||||
table = fresh_db["has_defaults"]
|
||||
table.insert({})
|
||||
|
||||
rows = list(table.rows)
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["id"] == 1
|
||||
assert rows[0]["name"] is None
|
||||
assert rows[0]["timestamp"] is not None
|
||||
assert rows[0]["is_active"] == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue