Support entrypoints for --load-extension (#473)

* Entrypoint support, closes #470
This commit is contained in:
Simon Willison 2022-08-26 22:55:47 -07:00 committed by GitHub
commit 19dd077944
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 145 additions and 41 deletions

View file

@ -94,7 +94,7 @@ def load_extension_option(fn):
return click.option(
"--load-extension",
multiple=True,
help="SQLite extensions to load",
help="Path to SQLite extension, with optional :entrypoint",
)(fn)
@ -2997,7 +2997,11 @@ def _load_extensions(db, load_extension):
for ext in load_extension:
if ext == "spatialite" and not os.path.exists(ext):
ext = find_spatialite()
db.conn.load_extension(ext)
if ":" in ext:
path, _, entrypoint = ext.partition(":")
db.conn.execute("SELECT load_extension(?, ?)", [path, entrypoint])
else:
db.conn.load_extension(ext)
def _register_functions(db, functions):