Skip to content

Commit 83f8bc2

Browse files
committed
A bunch of minor fixes
1 parent 4106264 commit 83f8bc2

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ This release introduces a new :ref:`plugin system <plugins>`. Read more about th
111111
3.32 (2023-05-21)
112112
-----------------
113113

114-
- New experimental ``sqlite-utils tui`` interface for interactively building command-line invocations, powered by `Trogon <https://github.com/Textualize/trogon>`__. This requires an optional dependency, installed using ``sqlite-utils install trogon``. (:issue:`545`)
114+
- New experimental ``sqlite-utils tui`` interface for interactively building command-line invocations, powered by `Trogon <https://github.com/Textualize/trogon>`__. This requires an optional dependency, installed using ``sqlite-utils install trogon``. There is a screenshot :ref:`in the documentation <cli_tui>`. (:issue:`545`)
115115
- ``sqlite-utils analyze-tables`` command (:ref:`documentation <cli_analyze_tables>`) now has a ``--common-limit 20`` option for changing the number of common/least-common values shown for each column. (:issue:`544`)
116116
- ``sqlite-utils analyze-tables --no-most`` and ``--no-least`` options for disabling calculation of most-common and least-common values.
117117
- If a column contains only ``null`` values, ``analyze-tables`` will no longer attempt to calculate the most common and least common values for that column. (:issue:`547`)

docs/cli-reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ This page lists the ``--help`` for every ``sqlite-utils`` CLI sub-command.
6565
"create-spatial-index": "cli_spatialite_indexes",
6666
"install": "cli_install",
6767
"uninstall": "cli_uninstall",
68+
"tui": "cli_tui",
6869
}
6970
commands.sort(key = lambda command: go_first.index(command) if command in go_first else 999)
7071
cog.out("\n")

docs/cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ You can set the ``SQLITE_UTILS_DETECT_TYPES`` environment variable if you want `
13011301
13021302
If a CSV or TSV file includes empty cells, like this one:
13031303

1304-
::
1304+
.. code-block:: csv
13051305
13061306
name,age,weight
13071307
Cleo,6,

sqlite_utils/cli.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ def insert_upsert_implementation(
962962
db = sqlite_utils.Database(path)
963963
_load_extensions(db, load_extension)
964964
if functions:
965-
_maybe_register_functions(db, functions)
965+
_register_functions_from_multiple(db, functions)
966966
if (delimiter or quotechar or sniff or no_headers) and not tsv:
967967
csv = True
968968
if (nl + csv + tsv) >= 2:
@@ -1800,7 +1800,7 @@ def query(
18001800
db.register_fts4_bm25()
18011801

18021802
if functions:
1803-
_maybe_register_functions(db, functions)
1803+
_register_functions_from_multiple(db, functions)
18041804

18051805
_execute_query(
18061806
db,
@@ -2002,7 +2002,7 @@ def memory(
20022002
db.register_fts4_bm25()
20032003

20042004
if functions:
2005-
_maybe_register_functions(db, functions)
2005+
_register_functions_from_multiple(db, functions)
20062006

20072007
if return_db:
20082008
return db
@@ -3306,16 +3306,10 @@ def _register_functions(db, functions):
33063306
db.register_function(value, name=name)
33073307

33083308

3309-
def _value_or_none(value):
3310-
if getattr(value, "__class__", None).__name__ == "Sentinel":
3311-
return None
3312-
return value
3313-
3314-
3315-
def _maybe_register_functions(db, functions_list):
3309+
def _register_functions_from_multiple(db, functions_list):
3310+
"""Register functions from multiple --functions arguments."""
33163311
if not functions_list:
33173312
return
33183313
for functions in functions_list:
3319-
functions = _value_or_none(functions)
33203314
if isinstance(functions, str) and functions.strip():
33213315
_register_functions(db, functions)

sqlite_utils/db.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,36 +237,43 @@ class Default:
237237

238238
class AlterError(Exception):
239239
"Error altering table"
240+
240241
pass
241242

242243

243244
class NoObviousTable(Exception):
244245
"Could not tell which table this operation refers to"
246+
245247
pass
246248

247249

248250
class NoTable(Exception):
249251
"Specified table does not exist"
252+
250253
pass
251254

252255

253256
class BadPrimaryKey(Exception):
254257
"Table does not have a single obvious primary key"
258+
255259
pass
256260

257261

258262
class NotFoundError(Exception):
259263
"Record not found"
264+
260265
pass
261266

262267

263268
class PrimaryKeyRequired(Exception):
264269
"Primary key needs to be specified"
270+
265271
pass
266272

267273

268274
class InvalidColumns(Exception):
269275
"Specified columns do not exist"
276+
270277
pass
271278

272279

@@ -3203,7 +3210,7 @@ def insert(
32033210
:param not_null: Set of strings specifying columns that should be ``NOT NULL``.
32043211
:param defaults: Dictionary specifying default values for specific columns.
32053212
:param hash_id: Name of a column to create and use as a primary key, where the
3206-
value of thet primary key will be derived as a SHA1 hash of the other column values
3213+
value of that primary key will be derived as a SHA1 hash of the other column values
32073214
in the record. ``hash_id="id"`` is a common column name used for this.
32083215
:param alter: Boolean, should any missing columns be added automatically?
32093216
:param ignore: Boolean, if a record already exists with this primary key, ignore this insert.
@@ -3852,7 +3859,7 @@ def jsonify_if_needed(value):
38523859

38533860

38543861
def resolve_extracts(
3855-
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]]
3862+
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]],
38563863
) -> dict:
38573864
if extracts is None:
38583865
extracts = {}

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def test_query_json_with_json_cols(db_path):
987987

988988
@pytest.mark.parametrize(
989989
"content,is_binary",
990-
[(b"\x00\x0Fbinary", True), ("this is text", False), (1, False), (1.5, False)],
990+
[(b"\x00\x0fbinary", True), ("this is text", False), (1, False), (1.5, False)],
991991
)
992992
def test_query_raw(db_path, content, is_binary):
993993
Database(db_path)["files"].insert({"content": content})
@@ -1002,7 +1002,7 @@ def test_query_raw(db_path, content, is_binary):
10021002

10031003
@pytest.mark.parametrize(
10041004
"content,is_binary",
1005-
[(b"\x00\x0Fbinary", True), ("this is text", False), (1, False), (1.5, False)],
1005+
[(b"\x00\x0fbinary", True), ("this is text", False), (1, False), (1.5, False)],
10061006
)
10071007
def test_query_raw_lines(db_path, content, is_binary):
10081008
Database(db_path)["files"].insert_all({"content": content} for _ in range(3))

0 commit comments

Comments
 (0)