sqlite-utils memory --schema, closes #288

Also updated some rowid examples, closes #287
This commit is contained in:
Simon Willison 2021-06-20 11:25:21 -07:00
commit 933be66eba
3 changed files with 76 additions and 46 deletions

View file

@ -1173,6 +1173,7 @@ def query(
is_flag=True,
help="Treat all CSV/TSV columns as TEXT",
)
@click.option("--schema", is_flag=True, help="Show SQL schema for in-memory database")
@click.option("--dump", is_flag=True, help="Dump SQL for in-memory database")
@click.option(
"--save",
@ -1196,6 +1197,7 @@ def memory(
param,
encoding,
no_detect_types,
schema,
dump,
save,
load_extension,
@ -1224,7 +1226,7 @@ def memory(
"""
db = sqlite_utils.Database(memory=True)
# If --dump or --save used but no paths detected, assume SQL query is a path:
if (dump or save) and not paths:
if (dump or save or schema) and not paths:
paths = [sql]
sql = None
for i, path in enumerate(paths):
@ -1262,6 +1264,10 @@ def memory(
click.echo(line)
return
if schema:
click.echo(db.schema)
return
if save:
db2 = sqlite_utils.Database(save)
for line in db.conn.iterdump():