mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
database.execute_write_fn(transaction=True) parameter, closes #2277
This commit is contained in:
parent
e1c80efff8
commit
5e0e440f2c
3 changed files with 60 additions and 13 deletions
|
|
@ -66,6 +66,33 @@ async def test_execute_fn(db):
|
|||
assert 2 == await db.execute_fn(get_1_plus_1)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_execute_fn_transaction_false():
|
||||
datasette = Datasette(memory=True)
|
||||
db = datasette.add_memory_database("test_execute_fn_transaction_false")
|
||||
|
||||
def run(conn):
|
||||
try:
|
||||
with conn:
|
||||
conn.execute("create table foo (id integer primary key)")
|
||||
conn.execute("insert into foo (id) values (44)")
|
||||
# Table should exist
|
||||
assert (
|
||||
conn.execute(
|
||||
'select count(*) from sqlite_master where name = "foo"'
|
||||
).fetchone()[0]
|
||||
== 1
|
||||
)
|
||||
assert conn.execute("select id from foo").fetchall()[0][0] == 44
|
||||
raise ValueError("Cancel commit")
|
||||
except ValueError:
|
||||
pass
|
||||
# Row should NOT exist
|
||||
assert conn.execute("select count(*) from foo").fetchone()[0] == 0
|
||||
|
||||
await db.execute_write_fn(run, transaction=False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tables,exists",
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue