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

@ -316,7 +316,7 @@ class Datasette:
}
)
def prepare_connection(self, conn):
def prepare_connection(self, conn, database):
conn.row_factory = sqlite3.Row
conn.text_factory = lambda x: str(x, "utf-8", "replace")
for name, num_args, func in self.sqlite_functions:
@ -328,7 +328,7 @@ class Datasette:
if self.config("cache_size_kb"):
conn.execute("PRAGMA cache_size=-{}".format(self.config("cache_size_kb")))
# pylint: disable=no-member
pm.hook.prepare_connection(conn=conn)
pm.hook.prepare_connection(conn=conn, database=database, datasette=self)
async def execute(
self,
@ -412,7 +412,7 @@ class Datasette:
def versions(self):
conn = sqlite3.connect(":memory:")
self.prepare_connection(conn)
self.prepare_connection(conn, ":memory:")
sqlite_version = conn.execute("select sqlite_version()").fetchone()[0]
sqlite_extensions = {}
for extension, testsql, hasversion in (