mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Improved .add_database() method design
Closes #1155 - _internal now has a sensible name Closes #509 - Support opening multiple databases with the same stem
This commit is contained in:
parent
270de6527b
commit
8919f99c2f
5 changed files with 86 additions and 46 deletions
|
|
@ -439,7 +439,7 @@ async def test_execute_write_fn_connection_exception(tmpdir, app_client):
|
|||
path = str(tmpdir / "immutable.db")
|
||||
sqlite3.connect(path).execute("vacuum")
|
||||
db = Database(app_client.ds, path=path, is_mutable=False)
|
||||
app_client.ds.add_database("immutable-db", db)
|
||||
app_client.ds.add_database(db, name="immutable-db")
|
||||
|
||||
def write_fn(conn):
|
||||
assert False
|
||||
|
|
@ -469,10 +469,10 @@ def test_is_mutable(app_client):
|
|||
@pytest.mark.asyncio
|
||||
async def test_database_memory_name(app_client):
|
||||
ds = app_client.ds
|
||||
foo1 = Database(ds, memory_name="foo")
|
||||
foo2 = Database(ds, memory_name="foo")
|
||||
bar1 = Database(ds, memory_name="bar")
|
||||
bar2 = Database(ds, memory_name="bar")
|
||||
foo1 = ds.add_database(Database(ds, memory_name="foo"))
|
||||
foo2 = ds.add_database(Database(ds, memory_name="foo"))
|
||||
bar1 = ds.add_database(Database(ds, memory_name="bar"))
|
||||
bar2 = ds.add_database(Database(ds, memory_name="bar"))
|
||||
for db in (foo1, foo2, bar1, bar2):
|
||||
table_names = await db.table_names()
|
||||
assert table_names == []
|
||||
|
|
@ -487,7 +487,7 @@ async def test_database_memory_name(app_client):
|
|||
@pytest.mark.asyncio
|
||||
async def test_in_memory_databases_forbid_writes(app_client):
|
||||
ds = app_client.ds
|
||||
db = Database(ds, memory_name="test")
|
||||
db = ds.add_database(Database(ds, memory_name="test"))
|
||||
with pytest.raises(sqlite3.OperationalError):
|
||||
await db.execute("create table foo (t text)")
|
||||
assert await db.table_names() == []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue