mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 16:56:27 +02:00
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
|
|
import sqlite3
|
||
|
|
from collections import OrderedDict
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.skipif(
|
||
|
|
sqlite3.sqlite_version_info[1] < 37,
|
||
|
|
reason="pragma_table_list was added in SQLite 3.37",
|
||
|
|
)
|
||
|
|
def test_shadow(db, snapshot):
|
||
|
|
db.execute(
|
||
|
|
"create virtual table v using vec0(a float[1], partition text partition key, metadata text, +name text, chunk_size=8)"
|
||
|
|
)
|
||
|
|
assert exec(db, "select * from sqlite_master order by name") == snapshot()
|
||
|
|
assert (
|
||
|
|
exec(db, "select * from pragma_table_list where type = 'shadow'") == snapshot()
|
||
|
|
)
|
||
|
|
|
||
|
|
db.execute("drop table v;")
|
||
|
|
assert (
|
||
|
|
exec(db, "select * from pragma_table_list where type = 'shadow'") == snapshot()
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def exec(db, sql, parameters=[]):
|
||
|
|
try:
|
||
|
|
rows = db.execute(sql, parameters).fetchall()
|
||
|
|
except (sqlite3.OperationalError, sqlite3.DatabaseError) as e:
|
||
|
|
return {
|
||
|
|
"error": e.__class__.__name__,
|
||
|
|
"message": str(e),
|
||
|
|
}
|
||
|
|
a = []
|
||
|
|
for row in rows:
|
||
|
|
o = OrderedDict()
|
||
|
|
for k in row.keys():
|
||
|
|
o[k] = row[k]
|
||
|
|
a.append(o)
|
||
|
|
result = OrderedDict()
|
||
|
|
result["sql"] = sql
|
||
|
|
result["rows"] = a
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
def vec0_shadow_table_contents(db, v):
|
||
|
|
shadow_tables = [
|
||
|
|
row[0]
|
||
|
|
for row in db.execute(
|
||
|
|
"select name from sqlite_master where name like ? order by 1", [f"{v}_%"]
|
||
|
|
).fetchall()
|
||
|
|
]
|
||
|
|
o = {}
|
||
|
|
for shadow_table in shadow_tables:
|
||
|
|
o[shadow_table] = exec(db, f"select * from {shadow_table}")
|
||
|
|
return o
|