mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Include count in execute_write_many traces, closes #1571
This commit is contained in:
parent
c6ff1f23e6
commit
f65817000f
3 changed files with 28 additions and 9 deletions
|
|
@ -114,11 +114,22 @@ class Database:
|
|||
|
||||
async def execute_write_many(self, sql, params_seq, block=False):
|
||||
def _inner(conn):
|
||||
with conn:
|
||||
return conn.executemany(sql, params_seq)
|
||||
count = 0
|
||||
|
||||
with trace("sql", database=self.name, sql=sql.strip(), executemany=True):
|
||||
results = await self.execute_write_fn(_inner, block=block)
|
||||
def count_params(params):
|
||||
nonlocal count
|
||||
for param in params:
|
||||
count += 1
|
||||
yield param
|
||||
|
||||
with conn:
|
||||
return conn.executemany(sql, count_params(params_seq)), count
|
||||
|
||||
with trace(
|
||||
"sql", database=self.name, sql=sql.strip(), executemany=True
|
||||
) as kwargs:
|
||||
results, count = await self.execute_write_fn(_inner, block=block)
|
||||
kwargs["count"] = count
|
||||
return results
|
||||
|
||||
async def execute_write_fn(self, fn, block=False):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue