db.execute_write(executescript=True) option, closes #1569

This commit is contained in:
Simon Willison 2021-12-18 10:28:25 -08:00
commit 9e094b7c9d
3 changed files with 31 additions and 4 deletions

View file

@ -663,8 +663,8 @@ Example usage:
.. _database_execute_write:
await db.execute_write(sql, params=None, block=False)
-----------------------------------------------------
await db.execute_write(sql, params=None, executescript=False, block=False)
--------------------------------------------------------------------------
SQLite only allows one database connection to write at a time. Datasette handles this for you by maintaining a queue of writes to be executed against a given database. Plugins can submit write operations to this queue and they will be executed in the order in which they are received.
@ -676,6 +676,8 @@ By default queries are considered to be "fire and forget" - they will be added t
If you pass ``block=True`` this behaviour changes: the method will block until the write operation has completed, and the return value will be the return from calling ``conn.execute(...)`` using the underlying ``sqlite3`` Python library.
If you pass ``executescript=True`` your SQL will be executed using the ``sqlite3`` `conn.executescript() <https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.executescript>`__ method. This allows multiple SQL statements to be separated by semicolons, but cannot be used with the ``params=`` option.
.. _database_execute_write_fn:
await db.execute_write_fn(fn, block=False)