mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-29 05:14:28 +02:00
Add tests for the create-update-trigger option.
This commit is contained in:
parent
aef825c140
commit
3816556782
2 changed files with 37 additions and 0 deletions
|
|
@ -329,6 +329,30 @@ def test_enable_fts(db_path):
|
||||||
assert "Gosh_fts" == Database(db_path)["Gosh"].detect_fts()
|
assert "Gosh_fts" == Database(db_path)["Gosh"].detect_fts()
|
||||||
|
|
||||||
|
|
||||||
|
def test_enable_fts_with_triggers(db_path):
|
||||||
|
Database(db_path)["Gosh"].insert_all([{"c1": "baz"}])
|
||||||
|
exit_code = (
|
||||||
|
CliRunner()
|
||||||
|
.invoke(
|
||||||
|
cli.cli,
|
||||||
|
["enable-fts", db_path, "Gosh", "c1", "--fts4", "--create-update-triggers"],
|
||||||
|
)
|
||||||
|
.exit_code
|
||||||
|
)
|
||||||
|
assert 0 == exit_code
|
||||||
|
|
||||||
|
def search(q):
|
||||||
|
return (
|
||||||
|
Database(db_path)
|
||||||
|
.conn.execute("select c1 from Gosh_fts where c1 match ?", [q])
|
||||||
|
.fetchall()
|
||||||
|
)
|
||||||
|
|
||||||
|
assert [("baz",)] == search("baz")
|
||||||
|
Database(db_path)["Gosh"].insert_all([{"c1": "martha"}])
|
||||||
|
assert [("martha",)] == search("martha")
|
||||||
|
|
||||||
|
|
||||||
def test_populate_fts(db_path):
|
def test_populate_fts(db_path):
|
||||||
Database(db_path)["Gosh"].insert_all([{"c1": "baz"}])
|
Database(db_path)["Gosh"].insert_all([{"c1": "baz"}])
|
||||||
exit_code = (
|
exit_code = (
|
||||||
|
|
|
||||||
|
|
@ -48,3 +48,16 @@ def test_optimize_fts(fresh_db):
|
||||||
"searchable_5_fts",
|
"searchable_5_fts",
|
||||||
):
|
):
|
||||||
fresh_db[table_name].optimize()
|
fresh_db[table_name].optimize()
|
||||||
|
|
||||||
|
|
||||||
|
def test_enable_fts_w_triggers(fresh_db):
|
||||||
|
table = fresh_db["searchable"]
|
||||||
|
table.insert(search_records[0])
|
||||||
|
table.enable_fts(
|
||||||
|
["text", "country"], fts_version="FTS4", create_update_triggers=True
|
||||||
|
)
|
||||||
|
assert [("tanuki are tricksters", "Japan", "foo")] == table.search("tanuki")
|
||||||
|
table.insert(search_records[1])
|
||||||
|
# Triggers will auto-populate FTS virtual table, not need to call populate_fts()
|
||||||
|
assert [("racoons are trash pandas", "USA", "bar")] == table.search("usa")
|
||||||
|
assert [] == table.search("bar")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue