sqlite-utils 3.37__tar.gz → 3.38a0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqlite_utils-3.37/sqlite_utils.egg-info → sqlite_utils-3.38a0}/PKG-INFO +1 -1
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/cli.rst +1 -1
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/plugins.rst +20 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/setup.py +1 -1
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/cli.py +7 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/db.py +5 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0/sqlite_utils.egg-info}/PKG-INFO +1 -1
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_cli_memory.py +14 -1
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/LICENSE +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/MANIFEST.in +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/README.md +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/changelog.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/cli-reference.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/contributing.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/index.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/installation.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/python-api.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/docs/reference.rst +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/setup.cfg +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/__init__.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/__main__.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/hookspecs.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/plugins.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/py.typed +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/recipes.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils/utils.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils.egg-info/SOURCES.txt +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils.egg-info/dependency_links.txt +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils.egg-info/entry_points.txt +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils.egg-info/not-zip-safe +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils.egg-info/requires.txt +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/sqlite_utils.egg-info/top_level.txt +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/__init__.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/conftest.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_analyze.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_analyze_tables.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_attach.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_cli.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_cli_bulk.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_cli_convert.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_cli_insert.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_column_affinity.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_constructor.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_conversions.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_convert.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_create.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_create_view.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_default_value.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_delete.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_docs.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_duplicate.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_enable_counts.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_extract.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_extracts.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_fts.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_get.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_gis.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_hypothesis.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_insert_files.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_introspect.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_lookup.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_m2m.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_plugins.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_query.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_recipes.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_recreate.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_register_function.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_rows.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_rows_from_file.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_sniff.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_suggest_column_types.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_tracer.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_transform.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_update.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_upsert.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_utils.py +0 -0
- {sqlite_utils-3.37 → sqlite_utils-3.38a0}/tests/test_wal.py +0 -0
|
@@ -2084,7 +2084,7 @@ Every option for this table (with the exception of ``--pk-none``) can be specifi
|
|
|
2084
2084
|
``--drop-foreign-key column``
|
|
2085
2085
|
Drop the specified foreign key.
|
|
2086
2086
|
|
|
2087
|
-
``--add-
|
|
2087
|
+
``--add-foreign-key column other_table other_column``
|
|
2088
2088
|
Add a foreign key constraint to ``column`` pointing to ``other_table.other_column``.
|
|
2089
2089
|
|
|
2090
2090
|
If you want to see the SQL that will be executed to make the change without actually executing it, add the ``--sql`` flag. For example:
|
|
@@ -115,6 +115,26 @@ Example implementation:
|
|
|
115
115
|
"Say hello world"
|
|
116
116
|
click.echo("Hello world!")
|
|
117
117
|
|
|
118
|
+
New commands implemented by plugins can invoke existing commands using the `context.invoke <https://click.palletsprojects.com/en/stable/api/#click.Context.invoke>`__ mechanism.
|
|
119
|
+
|
|
120
|
+
As a special niche feature, if your plugin needs to import some files and then act against an in-memory database containing those files you can forward to the :ref:`sqlite-utils memory command <cli_memory>` and pass it ``return_db=True``:
|
|
121
|
+
|
|
122
|
+
.. code-block:: python
|
|
123
|
+
|
|
124
|
+
@cli.command()
|
|
125
|
+
@click.pass_context
|
|
126
|
+
@click.argument(
|
|
127
|
+
"paths",
|
|
128
|
+
type=click.Path(file_okay=True, dir_okay=False, allow_dash=True),
|
|
129
|
+
required=False,
|
|
130
|
+
nargs=-1,
|
|
131
|
+
)
|
|
132
|
+
def show_schema_for_files(ctx, paths):
|
|
133
|
+
from sqlite_utils.cli import memory
|
|
134
|
+
db = ctx.invoke(memory, paths=paths, return_db=True)
|
|
135
|
+
# Now do something with that database
|
|
136
|
+
click.echo(db.schema)
|
|
137
|
+
|
|
118
138
|
.. _plugins_hooks_prepare_connection:
|
|
119
139
|
|
|
120
140
|
prepare_connection(conn)
|
|
@@ -1894,6 +1894,7 @@ def memory(
|
|
|
1894
1894
|
save,
|
|
1895
1895
|
analyze,
|
|
1896
1896
|
load_extension,
|
|
1897
|
+
return_db=False,
|
|
1897
1898
|
):
|
|
1898
1899
|
"""Execute SQL query against an in-memory database, optionally populated by imported data
|
|
1899
1900
|
|
|
@@ -1922,6 +1923,7 @@ def memory(
|
|
|
1922
1923
|
sqlite-utils memory animals.csv --schema
|
|
1923
1924
|
"""
|
|
1924
1925
|
db = sqlite_utils.Database(memory=True)
|
|
1926
|
+
|
|
1925
1927
|
# If --dump or --save or --analyze used but no paths detected, assume SQL query is a path:
|
|
1926
1928
|
if (dump or save or schema or analyze) and not paths:
|
|
1927
1929
|
paths = [sql]
|
|
@@ -1954,6 +1956,7 @@ def memory(
|
|
|
1954
1956
|
rows = tracker.wrap(rows)
|
|
1955
1957
|
if flatten:
|
|
1956
1958
|
rows = (_flatten(row) for row in rows)
|
|
1959
|
+
|
|
1957
1960
|
db[file_table].insert_all(rows, alter=True)
|
|
1958
1961
|
if tracker is not None:
|
|
1959
1962
|
db[file_table].transform(types=tracker.types)
|
|
@@ -1964,6 +1967,7 @@ def memory(
|
|
|
1964
1967
|
for view_name in view_names:
|
|
1965
1968
|
if not db[view_name].exists():
|
|
1966
1969
|
db.create_view(view_name, "select * from [{}]".format(file_table))
|
|
1970
|
+
|
|
1967
1971
|
if fp:
|
|
1968
1972
|
fp.close()
|
|
1969
1973
|
|
|
@@ -1994,6 +1998,9 @@ def memory(
|
|
|
1994
1998
|
if functions:
|
|
1995
1999
|
_register_functions(db, functions)
|
|
1996
2000
|
|
|
2001
|
+
if return_db:
|
|
2002
|
+
return db
|
|
2003
|
+
|
|
1997
2004
|
_execute_query(
|
|
1998
2005
|
db,
|
|
1999
2006
|
sql,
|
|
@@ -325,6 +325,8 @@ class Database:
|
|
|
325
325
|
execute_plugins: bool = True,
|
|
326
326
|
strict: bool = False,
|
|
327
327
|
):
|
|
328
|
+
self.memory_name = None
|
|
329
|
+
self.memory = False
|
|
328
330
|
assert (filename_or_conn is not None and (not memory and not memory_name)) or (
|
|
329
331
|
filename_or_conn is None and (memory or memory_name)
|
|
330
332
|
), "Either specify a filename_or_conn or pass memory=True"
|
|
@@ -335,8 +337,11 @@ class Database:
|
|
|
335
337
|
uri=True,
|
|
336
338
|
check_same_thread=False,
|
|
337
339
|
)
|
|
340
|
+
self.memory = True
|
|
341
|
+
self.memory_name = memory_name
|
|
338
342
|
elif memory or filename_or_conn == ":memory:":
|
|
339
343
|
self.conn = sqlite3.connect(":memory:")
|
|
344
|
+
self.memory = True
|
|
340
345
|
elif isinstance(filename_or_conn, (str, pathlib.Path)):
|
|
341
346
|
if recreate and os.path.exists(filename_or_conn):
|
|
342
347
|
try:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import click
|
|
1
2
|
import json
|
|
2
|
-
|
|
3
3
|
import pytest
|
|
4
4
|
from click.testing import CliRunner
|
|
5
5
|
|
|
@@ -305,3 +305,16 @@ def test_memory_functions():
|
|
|
305
305
|
)
|
|
306
306
|
assert result.exit_code == 0
|
|
307
307
|
assert result.output.strip() == '[{"hello()": "Hello"}]'
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def test_memory_return_db(tmpdir):
|
|
311
|
+
# https://github.com/simonw/sqlite-utils/issues/643
|
|
312
|
+
from sqlite_utils.cli import cli
|
|
313
|
+
|
|
314
|
+
path = str(tmpdir / "dogs.csv")
|
|
315
|
+
open(path, "w").write("id,name\n1,Cleo")
|
|
316
|
+
|
|
317
|
+
with click.Context(cli) as ctx:
|
|
318
|
+
db = ctx.invoke(cli.commands["memory"], paths=(path,), return_db=True)
|
|
319
|
+
|
|
320
|
+
assert db.table_names() == ["dogs"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|