prepare_connection() now takes datasette and database args, refs #678

This commit is contained in:
Simon Willison 2020-02-21 17:32:40 -08:00
commit 6303ea5048
5 changed files with 16 additions and 8 deletions

View file

@ -340,12 +340,18 @@ The full list of available plugin hooks is as follows.
.. _plugin_hook_prepare_connection:
prepare_connection(conn)
~~~~~~~~~~~~~~~~~~~~~~~~
prepare_connection(conn, database, datasette)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``conn`` - sqlite3 connection object
The connection that is being opened
``database`` - string
The name of the database
``datasette`` - :ref:`datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
This hook is called when a new SQLite database connection is created. You can
use it to `register custom SQL functions <https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.create_function>`_,
aggregates and collations. For example: