database.triggers_dict, closes #216

This commit is contained in:
Simon Willison 2021-01-02 20:19:55 -08:00
commit de08096989
3 changed files with 23 additions and 6 deletions

View file

@ -127,9 +127,10 @@ def test_triggers_and_triggers_dict(fresh_db):
]
)
fresh_db["other"].insert({"foo": "bar"})
assert [] == authors.triggers
assert {} == authors.triggers_dict
assert [] == fresh_db["other"].triggers
assert authors.triggers == []
assert authors.triggers_dict == {}
assert fresh_db["other"].triggers == []
assert fresh_db.triggers_dict == {}
authors.enable_fts(
["name", "famous_works"], fts_version="FTS4", create_triggers=True
)
@ -142,13 +143,15 @@ def test_triggers_and_triggers_dict(fresh_db):
assert expected_triggers == {
(t.name, t.table) for t in fresh_db["authors"].triggers
}
assert authors.triggers_dict == {
expected_triggers = {
"authors_ai": "CREATE TRIGGER [authors_ai] AFTER INSERT ON [authors] BEGIN\n INSERT INTO [authors_fts] (rowid, [name], [famous_works]) VALUES (new.rowid, new.[name], new.[famous_works]);\nEND",
"authors_ad": "CREATE TRIGGER [authors_ad] AFTER DELETE ON [authors] BEGIN\n INSERT INTO [authors_fts] ([authors_fts], rowid, [name], [famous_works]) VALUES('delete', old.rowid, old.[name], old.[famous_works]);\nEND",
"authors_au": "CREATE TRIGGER [authors_au] AFTER UPDATE ON [authors] BEGIN\n INSERT INTO [authors_fts] ([authors_fts], rowid, [name], [famous_works]) VALUES('delete', old.rowid, old.[name], old.[famous_works]);\n INSERT INTO [authors_fts] (rowid, [name], [famous_works]) VALUES (new.rowid, new.[name], new.[famous_works]);\nEND",
}
assert [] == fresh_db["other"].triggers
assert {} == fresh_db["other"].triggers_dict
assert authors.triggers_dict == expected_triggers
assert fresh_db["other"].triggers == []
assert fresh_db["other"].triggers_dict == {}
assert fresh_db.triggers_dict == expected_triggers
@pytest.mark.parametrize(