mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
prepare_connection plugin hook
Closes: - #574 Refs #567 --------- Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
parent
091c63cfbf
commit
3f80a02698
5 changed files with 79 additions and 3 deletions
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue