A bunch of minor fixes

This commit is contained in:
Simon Willison 2025-11-24 09:44:34 -08:00
commit 83f8bc2eaa
6 changed files with 19 additions and 17 deletions

View file

@ -962,7 +962,7 @@ def insert_upsert_implementation(
db = sqlite_utils.Database(path)
_load_extensions(db, load_extension)
if functions:
_maybe_register_functions(db, functions)
_register_functions_from_multiple(db, functions)
if (delimiter or quotechar or sniff or no_headers) and not tsv:
csv = True
if (nl + csv + tsv) >= 2:
@ -1800,7 +1800,7 @@ def query(
db.register_fts4_bm25()
if functions:
_maybe_register_functions(db, functions)
_register_functions_from_multiple(db, functions)
_execute_query(
db,
@ -2002,7 +2002,7 @@ def memory(
db.register_fts4_bm25()
if functions:
_maybe_register_functions(db, functions)
_register_functions_from_multiple(db, functions)
if return_db:
return db
@ -3306,16 +3306,10 @@ def _register_functions(db, functions):
db.register_function(value, name=name)
def _value_or_none(value):
if getattr(value, "__class__", None).__name__ == "Sentinel":
return None
return value
def _maybe_register_functions(db, functions_list):
def _register_functions_from_multiple(db, functions_list):
"""Register functions from multiple --functions arguments."""
if not functions_list:
return
for functions in functions_list:
functions = _value_or_none(functions)
if isinstance(functions, str) and functions.strip():
_register_functions(db, functions)

View file

@ -237,36 +237,43 @@ if pd:
class AlterError(Exception):
"Error altering table"
pass
class NoObviousTable(Exception):
"Could not tell which table this operation refers to"
pass
class NoTable(Exception):
"Specified table does not exist"
pass
class BadPrimaryKey(Exception):
"Table does not have a single obvious primary key"
pass
class NotFoundError(Exception):
"Record not found"
pass
class PrimaryKeyRequired(Exception):
"Primary key needs to be specified"
pass
class InvalidColumns(Exception):
"Specified columns do not exist"
pass
@ -3203,7 +3210,7 @@ class Table(Queryable):
:param not_null: Set of strings specifying columns that should be ``NOT NULL``.
:param defaults: Dictionary specifying default values for specific columns.
:param hash_id: Name of a column to create and use as a primary key, where the
value of thet primary key will be derived as a SHA1 hash of the other column values
value of that primary key will be derived as a SHA1 hash of the other column values
in the record. ``hash_id="id"`` is a common column name used for this.
:param alter: Boolean, should any missing columns be added automatically?
:param ignore: Boolean, if a record already exists with this primary key, ignore this insert.
@ -3852,7 +3859,7 @@ def jsonify_if_needed(value):
def resolve_extracts(
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]]
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]],
) -> dict:
if extracts is None:
extracts = {}