mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-25 10:24:32 +02:00
-p for passing named params to query, closes #124
This commit is contained in:
parent
20e543e9a4
commit
814d4a7f90
3 changed files with 35 additions and 2 deletions
|
|
@ -677,11 +677,18 @@ def drop_view(path, view):
|
|||
@click.argument("sql")
|
||||
@output_options
|
||||
@click.option("-r", "--raw", is_flag=True, help="Raw output, first column of first row")
|
||||
def query(path, sql, nl, arrays, csv, no_headers, table, fmt, json_cols, raw):
|
||||
@click.option(
|
||||
"-p",
|
||||
"--param",
|
||||
multiple=True,
|
||||
type=(str, str),
|
||||
help="Named :parameters for SQL query",
|
||||
)
|
||||
def query(path, sql, nl, arrays, csv, no_headers, table, fmt, json_cols, raw, param):
|
||||
"Execute SQL query and return the results as JSON"
|
||||
db = sqlite_utils.Database(path)
|
||||
with db.conn:
|
||||
cursor = db.conn.execute(sql)
|
||||
cursor = db.conn.execute(sql, dict(param))
|
||||
if cursor.description is None:
|
||||
# This was an update/insert
|
||||
headers = ["rows_affected"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue