mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 18:04:32 +02:00
--load-extension option for sqlite-utils query, closes #134
This commit is contained in:
parent
bf4c6b7c82
commit
7e9aad7e1c
3 changed files with 50 additions and 2 deletions
|
|
@ -719,9 +719,29 @@ def drop_view(path, view):
|
|||
type=(str, str),
|
||||
help="Named :parameters for SQL query",
|
||||
)
|
||||
def query(path, sql, nl, arrays, csv, no_headers, table, fmt, json_cols, raw, param):
|
||||
@click.option(
|
||||
"--load-extension", multiple=True, help="SQLite extensions to load",
|
||||
)
|
||||
def query(
|
||||
path,
|
||||
sql,
|
||||
nl,
|
||||
arrays,
|
||||
csv,
|
||||
no_headers,
|
||||
table,
|
||||
fmt,
|
||||
json_cols,
|
||||
raw,
|
||||
param,
|
||||
load_extension,
|
||||
):
|
||||
"Execute SQL query and return the results as JSON"
|
||||
db = sqlite_utils.Database(path)
|
||||
if load_extension:
|
||||
db.conn.enable_load_extension(True)
|
||||
for ext in load_extension:
|
||||
db.conn.load_extension(ext)
|
||||
with db.conn:
|
||||
cursor = db.conn.execute(sql, dict(param))
|
||||
if cursor.description is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue