Add new entrypoint option to --load-extensions. (#1789)

Thanks, @asg017
This commit is contained in:
Alex Garcia 2022-08-23 11:34:30 -07:00 committed by GitHub
commit 1d64c9a8da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 140 additions and 2 deletions

View file

@ -559,7 +559,13 @@ class Datasette:
if self.sqlite_extensions:
conn.enable_load_extension(True)
for extension in self.sqlite_extensions:
conn.execute("SELECT load_extension(?)", [extension])
# "extension" is either a string path to the extension
# or a 2-item tuple that specifies which entrypoint to load.
if isinstance(extension, tuple):
path, entrypoint = extension
conn.execute("SELECT load_extension(?, ?)", [path, entrypoint])
else:
conn.execute("SELECT load_extension(?)", [extension])
if self.setting("cache_size_kb"):
conn.execute(f"PRAGMA cache_size=-{self.setting('cache_size_kb')}")
# pylint: disable=no-member