mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Add new entrypoint option to --load-extensions. (#1789)
Thanks, @asg017
This commit is contained in:
parent
663ac431fe
commit
1d64c9a8da
6 changed files with 140 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from .app import (
|
|||
pm,
|
||||
)
|
||||
from .utils import (
|
||||
LoadExtension,
|
||||
StartupError,
|
||||
check_connection,
|
||||
find_spatialite,
|
||||
|
|
@ -128,9 +129,10 @@ def sqlite_extensions(fn):
|
|||
return click.option(
|
||||
"sqlite_extensions",
|
||||
"--load-extension",
|
||||
type=LoadExtension(),
|
||||
envvar="SQLITE_EXTENSIONS",
|
||||
multiple=True,
|
||||
help="Path to a SQLite extension to load",
|
||||
help="Path to a SQLite extension to load, and optional entrypoint",
|
||||
)(fn)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -833,6 +833,17 @@ class StaticMount(click.ParamType):
|
|||
self.fail(f"{value} is not a valid directory path", param, ctx)
|
||||
return path, dirpath
|
||||
|
||||
# The --load-extension parameter can optionally include a specific entrypoint.
|
||||
# This is done by appending ":entrypoint_name" after supplying the path to the extension
|
||||
class LoadExtension(click.ParamType):
|
||||
name = "path:entrypoint?"
|
||||
|
||||
def convert(self, value, param, ctx):
|
||||
if ":" not in value:
|
||||
return value
|
||||
path, entrypoint = value.split(":", 1)
|
||||
return path, entrypoint
|
||||
|
||||
|
||||
def format_bytes(bytes):
|
||||
current = float(bytes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue