2021-02-18 20:56:32 -08:00
|
|
|
from sqlite_utils import Database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_attach(tmpdir):
|
|
|
|
|
foo_path = str(tmpdir / "foo.db")
|
|
|
|
|
bar_path = str(tmpdir / "bar.db")
|
|
|
|
|
db = Database(foo_path)
|
|
|
|
|
with db.conn:
|
2026-08-12 13:40:55 -07:00
|
|
|
db.table("foo").insert({"id": 1, "text": "foo"})
|
2021-02-18 20:56:32 -08:00
|
|
|
db2 = Database(bar_path)
|
|
|
|
|
with db2.conn:
|
2026-08-12 13:40:55 -07:00
|
|
|
db2.table("bar").insert({"id": 1, "text": "bar"})
|
2021-02-18 20:56:32 -08:00
|
|
|
db.attach("bar", bar_path)
|
|
|
|
|
assert db.execute(
|
|
|
|
|
"select * from foo union all select * from bar.bar"
|
|
|
|
|
).fetchall() == [(1, "foo"), (1, "bar")]
|