sections
1 row where breadcrumbs = "["Internals for plugins", "Database class"]", page = "internals" and title = "await db.execute_write_fn(fn, block=True, transaction=True)"
This data as json, CSV (advanced)
Suggested facets: breadcrumbs (array)
| id ▼ | page | ref | title | content | breadcrumbs | references |
|---|---|---|---|---|---|---|
| internals:database-execute-write-fn | internals | database-execute-write-fn | await db.execute_write_fn(fn, block=True, transaction=True) | This method works like .execute_write() , but instead of a SQL statement you give it a callable Python function. Your function will be queued up and then called when the write connection is available, passing that connection as the argument to the function. The function can then perform multiple actions, safe in the knowledge that it has exclusive access to the single writable connection for as long as it is executing. fn needs to be a regular function, not an async def function. For example: def delete_and_return_count(conn): conn.execute("delete from some_table where id > 5") return conn.execute( "select count(*) from some_table" ).fetchone()[0] try: num_rows_left = await database.execute_write_fn( delete_and_return_count ) except Exception as e: print("An error occurred:", e) Your function can optionally accept a track_event parameter in addition to conn . If it does, it will be passed a callable that can be used to queue events for dispatch after the write transaction commits successfully. Events queued this way are discarded if the write raises an exception. from datasette.events import AlterTableEvent def my_write(conn, track_event): before_schema = conn.execute( "select sql from sqlite_master where name = 'my_table'" ).fetchone()[0] conn.execute( "alter table my_table add column new_col text" ) after_schema = conn.execute( "select sql from sqlite_master where name = 'my_table'" ).fetchone()[0] track_event( AlterTableEvent( actor=None, database="mydb", table="my_table", before_schema=before_schema, after_schema=after_schema, ) ) await database.execute_write_fn(my_write) The value returned from await database.execute_write_fn(...) will be the return value from… | ["Internals for plugins", "Database class"] | [] |
Advanced export
JSON shape: default, array, newline-delimited, object
CREATE TABLE [sections] ( [id] TEXT PRIMARY KEY, [page] TEXT, [ref] TEXT, [title] TEXT, [content] TEXT, [breadcrumbs] TEXT, [references] TEXT );