sqlite-utils 3.37__py3-none-any.whl → 3.38__py3-none-any.whl
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/cli.py +7 -0
- sqlite_utils/db.py +42 -1
- {sqlite_utils-3.37.dist-info → sqlite_utils-3.38.dist-info}/METADATA +22 -22
- {sqlite_utils-3.37.dist-info → sqlite_utils-3.38.dist-info}/RECORD +8 -8
- {sqlite_utils-3.37.dist-info → sqlite_utils-3.38.dist-info}/WHEEL +1 -1
- {sqlite_utils-3.37.dist-info → sqlite_utils-3.38.dist-info}/LICENSE +0 -0
- {sqlite_utils-3.37.dist-info → sqlite_utils-3.38.dist-info}/entry_points.txt +0 -0
- {sqlite_utils-3.37.dist-info → sqlite_utils-3.38.dist-info}/top_level.txt +0 -0
sqlite_utils/cli.py
CHANGED
|
@@ -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,
|
sqlite_utils/db.py
CHANGED
|
@@ -156,6 +156,10 @@ XIndexColumn = namedtuple(
|
|
|
156
156
|
Trigger = namedtuple("Trigger", ("name", "table", "sql"))
|
|
157
157
|
|
|
158
158
|
|
|
159
|
+
class TransformError(Exception):
|
|
160
|
+
pass
|
|
161
|
+
|
|
162
|
+
|
|
159
163
|
ForeignKeyIndicator = Union[
|
|
160
164
|
str,
|
|
161
165
|
ForeignKey,
|
|
@@ -325,6 +329,8 @@ class Database:
|
|
|
325
329
|
execute_plugins: bool = True,
|
|
326
330
|
strict: bool = False,
|
|
327
331
|
):
|
|
332
|
+
self.memory_name = None
|
|
333
|
+
self.memory = False
|
|
328
334
|
assert (filename_or_conn is not None and (not memory and not memory_name)) or (
|
|
329
335
|
filename_or_conn is None and (memory or memory_name)
|
|
330
336
|
), "Either specify a filename_or_conn or pass memory=True"
|
|
@@ -335,8 +341,11 @@ class Database:
|
|
|
335
341
|
uri=True,
|
|
336
342
|
check_same_thread=False,
|
|
337
343
|
)
|
|
344
|
+
self.memory = True
|
|
345
|
+
self.memory_name = memory_name
|
|
338
346
|
elif memory or filename_or_conn == ":memory:":
|
|
339
347
|
self.conn = sqlite3.connect(":memory:")
|
|
348
|
+
self.memory = True
|
|
340
349
|
elif isinstance(filename_or_conn, (str, pathlib.Path)):
|
|
341
350
|
if recreate and os.path.exists(filename_or_conn):
|
|
342
351
|
try:
|
|
@@ -929,10 +938,15 @@ class Database:
|
|
|
929
938
|
other_column=foreign_keys_by_column[column_name].other_column,
|
|
930
939
|
)
|
|
931
940
|
)
|
|
941
|
+
column_type_str = COLUMN_TYPE_MAPPING[column_type]
|
|
942
|
+
# Special case for strict tables to map FLOAT to REAL
|
|
943
|
+
# Refs https://github.com/simonw/sqlite-utils/issues/644
|
|
944
|
+
if strict and column_type_str == "FLOAT":
|
|
945
|
+
column_type_str = "REAL"
|
|
932
946
|
column_defs.append(
|
|
933
947
|
" [{column_name}] {column_type}{column_extras}".format(
|
|
934
948
|
column_name=column_name,
|
|
935
|
-
column_type=
|
|
949
|
+
column_type=column_type_str,
|
|
936
950
|
column_extras=(
|
|
937
951
|
(" " + " ".join(column_extras)) if column_extras else ""
|
|
938
952
|
),
|
|
@@ -1967,6 +1981,30 @@ class Table(Queryable):
|
|
|
1967
1981
|
sqls.append(
|
|
1968
1982
|
"ALTER TABLE [{}] RENAME TO [{}];".format(new_table_name, self.name)
|
|
1969
1983
|
)
|
|
1984
|
+
# Re-add existing indexes
|
|
1985
|
+
for index in self.indexes:
|
|
1986
|
+
if index.origin != "pk":
|
|
1987
|
+
index_sql = self.db.execute(
|
|
1988
|
+
"""SELECT sql FROM sqlite_master WHERE type = 'index' AND name = :index_name;""",
|
|
1989
|
+
{"index_name": index.name},
|
|
1990
|
+
).fetchall()[0][0]
|
|
1991
|
+
if index_sql is None:
|
|
1992
|
+
raise TransformError(
|
|
1993
|
+
f"Index '{index.name}' on table '{self.name}' does not have a "
|
|
1994
|
+
"CREATE INDEX statement. You must manually drop this index prior to running this "
|
|
1995
|
+
"transformation and manually recreate the new index after running this transformation."
|
|
1996
|
+
)
|
|
1997
|
+
if keep_table:
|
|
1998
|
+
sqls.append(f"DROP INDEX IF EXISTS [{index.name}];")
|
|
1999
|
+
for col in index.columns:
|
|
2000
|
+
if col in rename.keys() or col in drop:
|
|
2001
|
+
raise TransformError(
|
|
2002
|
+
f"Index '{index.name}' column '{col}' is not in updated table '{self.name}'. "
|
|
2003
|
+
f"You must manually drop this index prior to running this transformation "
|
|
2004
|
+
f"and manually recreate the new index after running this transformation. "
|
|
2005
|
+
f"The original index sql statement is: `{index_sql}`. No changes have been applied to this table."
|
|
2006
|
+
)
|
|
2007
|
+
sqls.append(index_sql)
|
|
1970
2008
|
return sqls
|
|
1971
2009
|
|
|
1972
2010
|
def extract(
|
|
@@ -2645,6 +2683,7 @@ class Table(Queryable):
|
|
|
2645
2683
|
offset: Optional[int] = None,
|
|
2646
2684
|
where: Optional[str] = None,
|
|
2647
2685
|
where_args: Optional[Union[Iterable, dict]] = None,
|
|
2686
|
+
include_rank: bool = False,
|
|
2648
2687
|
quote: bool = False,
|
|
2649
2688
|
) -> Generator[dict, None, None]:
|
|
2650
2689
|
"""
|
|
@@ -2658,6 +2697,7 @@ class Table(Queryable):
|
|
|
2658
2697
|
:param offset: Optional integer SQL offset.
|
|
2659
2698
|
:param where: Extra SQL fragment for the WHERE clause
|
|
2660
2699
|
:param where_args: Arguments to use for :param placeholders in the extra WHERE clause
|
|
2700
|
+
:param include_rank: Select the search rank column in the final query
|
|
2661
2701
|
:param quote: Apply quoting to disable any special characters in the search query
|
|
2662
2702
|
|
|
2663
2703
|
See :ref:`python_api_fts_search`.
|
|
@@ -2677,6 +2717,7 @@ class Table(Queryable):
|
|
|
2677
2717
|
limit=limit,
|
|
2678
2718
|
offset=offset,
|
|
2679
2719
|
where=where,
|
|
2720
|
+
include_rank=include_rank,
|
|
2680
2721
|
),
|
|
2681
2722
|
args,
|
|
2682
2723
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sqlite-utils
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.38
|
|
4
4
|
Summary: CLI tool and Python library for manipulating SQLite databases
|
|
5
5
|
Home-page: https://github.com/simonw/sqlite-utils
|
|
6
6
|
Author: Simon Willison
|
|
@@ -27,33 +27,33 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
License-File: LICENSE
|
|
28
28
|
Requires-Dist: sqlite-fts4
|
|
29
29
|
Requires-Dist: click
|
|
30
|
-
Requires-Dist: click-default-group
|
|
30
|
+
Requires-Dist: click-default-group>=1.2.3
|
|
31
31
|
Requires-Dist: tabulate
|
|
32
32
|
Requires-Dist: python-dateutil
|
|
33
33
|
Requires-Dist: pluggy
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: pytest; extra == "test"
|
|
36
|
+
Requires-Dist: black>=24.1.1; extra == "test"
|
|
37
|
+
Requires-Dist: hypothesis; extra == "test"
|
|
38
|
+
Requires-Dist: cogapp; extra == "test"
|
|
34
39
|
Provides-Extra: docs
|
|
35
|
-
Requires-Dist: furo
|
|
36
|
-
Requires-Dist: sphinx-autobuild
|
|
37
|
-
Requires-Dist: codespell
|
|
38
|
-
Requires-Dist: sphinx-copybutton
|
|
39
|
-
Requires-Dist: beanbag-docutils
|
|
40
|
-
Requires-Dist: pygments-csv-lexer
|
|
41
|
-
Provides-Extra: flake8
|
|
42
|
-
Requires-Dist: flake8 ; extra == 'flake8'
|
|
40
|
+
Requires-Dist: furo; extra == "docs"
|
|
41
|
+
Requires-Dist: sphinx-autobuild; extra == "docs"
|
|
42
|
+
Requires-Dist: codespell; extra == "docs"
|
|
43
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
44
|
+
Requires-Dist: beanbag-docutils>=2.0; extra == "docs"
|
|
45
|
+
Requires-Dist: pygments-csv-lexer; extra == "docs"
|
|
43
46
|
Provides-Extra: mypy
|
|
44
|
-
Requires-Dist: mypy
|
|
45
|
-
Requires-Dist: types-click
|
|
46
|
-
Requires-Dist: types-tabulate
|
|
47
|
-
Requires-Dist: types-python-dateutil
|
|
48
|
-
Requires-Dist: types-pluggy
|
|
49
|
-
Requires-Dist: data-science-types
|
|
50
|
-
Provides-Extra:
|
|
51
|
-
Requires-Dist:
|
|
52
|
-
Requires-Dist: black >=24.1.1 ; extra == 'test'
|
|
53
|
-
Requires-Dist: hypothesis ; extra == 'test'
|
|
54
|
-
Requires-Dist: cogapp ; extra == 'test'
|
|
47
|
+
Requires-Dist: mypy; extra == "mypy"
|
|
48
|
+
Requires-Dist: types-click; extra == "mypy"
|
|
49
|
+
Requires-Dist: types-tabulate; extra == "mypy"
|
|
50
|
+
Requires-Dist: types-python-dateutil; extra == "mypy"
|
|
51
|
+
Requires-Dist: types-pluggy; extra == "mypy"
|
|
52
|
+
Requires-Dist: data-science-types; extra == "mypy"
|
|
53
|
+
Provides-Extra: flake8
|
|
54
|
+
Requires-Dist: flake8; extra == "flake8"
|
|
55
55
|
Provides-Extra: tui
|
|
56
|
-
Requires-Dist: trogon
|
|
56
|
+
Requires-Dist: trogon; extra == "tui"
|
|
57
57
|
|
|
58
58
|
# sqlite-utils
|
|
59
59
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
sqlite_utils/__init__.py,sha256=eyDK-5KOo-ARS3i0JcuxGiJmk5T-58Z1p_bhACbBrGc,201
|
|
2
2
|
sqlite_utils/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
|
|
3
|
-
sqlite_utils/cli.py,sha256=
|
|
4
|
-
sqlite_utils/db.py,sha256=
|
|
3
|
+
sqlite_utils/cli.py,sha256=r1cQ70T1KE-0va-ob-AC76Rr81SaSeEVOKp3FAbyPHM,89832
|
|
4
|
+
sqlite_utils/db.py,sha256=6minoeWeXkdVS7XwFUUPymePwYtOokwrVIn0qZ1HiI0,148509
|
|
5
5
|
sqlite_utils/hookspecs.py,sha256=NFA0BFZ8WUhnI_NRz4oFVDcomQYlguuAgUCBKAN792o,395
|
|
6
6
|
sqlite_utils/plugins.py,sha256=V5nXD4r0o1wSbIHHOAiUBBV66ZOfKVnywKfZzCUqdsA,771
|
|
7
7
|
sqlite_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
sqlite_utils/recipes.py,sha256=_npzti0nPV6XxvMj69Ca4QF-pXwZZQp_f_VY3i7pQDs,1687
|
|
9
9
|
sqlite_utils/utils.py,sha256=PRqoITtqmaUI7xzyB2exaTPg6oXbTMhGDzld7srNOG4,17099
|
|
10
|
-
sqlite_utils-3.
|
|
11
|
-
sqlite_utils-3.
|
|
12
|
-
sqlite_utils-3.
|
|
13
|
-
sqlite_utils-3.
|
|
14
|
-
sqlite_utils-3.
|
|
15
|
-
sqlite_utils-3.
|
|
10
|
+
sqlite_utils-3.38.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
+
sqlite_utils-3.38.dist-info/METADATA,sha256=12ik5_GloHZ2sO5GCbvFjzQVU1NG_zubIMPfF6V35k4,7540
|
|
12
|
+
sqlite_utils-3.38.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
13
|
+
sqlite_utils-3.38.dist-info/entry_points.txt,sha256=33jbVHROlRBNhoXoSI-QI2rN6JDkJIkKIX7P5sNIWdY,54
|
|
14
|
+
sqlite_utils-3.38.dist-info/top_level.txt,sha256=_dw_n5BWKUEtCYB2DTlmPMQfdRZSuFsmRQe2ZhNYwnQ,13
|
|
15
|
+
sqlite_utils-3.38.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|