mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
db.execute_write(executescript=True) option, closes #1569
This commit is contained in:
parent
85c22f4fbc
commit
9e094b7c9d
3 changed files with 31 additions and 4 deletions
|
|
@ -94,10 +94,14 @@ class Database:
|
|||
f"file:{self.path}{qs}", uri=True, check_same_thread=False
|
||||
)
|
||||
|
||||
async def execute_write(self, sql, params=None, block=False):
|
||||
async def execute_write(self, sql, params=None, executescript=False, block=False):
|
||||
assert not (executescript and params), "Cannot use params with executescript=True"
|
||||
def _inner(conn):
|
||||
with conn:
|
||||
return conn.execute(sql, params or [])
|
||||
if executescript:
|
||||
return conn.executescript(sql)
|
||||
else:
|
||||
return conn.execute(sql, params or [])
|
||||
|
||||
with trace("sql", database=self.name, sql=sql.strip(), params=params):
|
||||
results = await self.execute_write_fn(_inner, block=block)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue