prepare_connection plugin hook

Closes:
- #574

Refs #567

---------

Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
Alex Garcia 2023-07-22 15:59:08 -07:00 committed by GitHub
commit 3f80a02698
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 3 deletions

View file

@ -1,6 +1,6 @@
from .db import Database
from .utils import suggest_column_types
from .hookspecs import hookimpl
from .hookspecs import hookspec
from .db import Database
__all__ = ["Database", "suggest_column_types", "hookimpl", "hookspec"]

View file

@ -37,6 +37,7 @@ from typing import (
Tuple,
)
import uuid
from sqlite_utils.plugins import pm
try:
from sqlite_dump import iterdump
@ -342,6 +343,8 @@ class Database:
self._registered_functions: set = set()
self.use_counts_table = use_counts_table
pm.hook.prepare_connection(conn=self.conn)
def close(self):
"Close the SQLite connection, and the underlying database file"
self.conn.close()

View file

@ -8,3 +8,8 @@ hookimpl = HookimplMarker("sqlite_utils")
@hookspec
def register_commands(cli):
"""Register additional CLI commands, e.g. 'sqlite-utils mycommand ...'"""
@hookspec
def prepare_connection(conn):
"""Modify SQLite connection in some way e.g. register custom SQL functions"""