Skip to content

Commit bcbda4a

Browse files
committed
docs: add docstrings to four undocumented public Database/Queryable methods
Add docstrings to quote_default_value, supports_on_conflict, execute_returning_dicts, and execute_count. All four are part of the public API but lacked any documentation, making their purpose and behaviour unclear from the source alone.
1 parent 8d74ffc commit bcbda4a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sqlite_utils/db.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,16 @@ def quote_fts(self, query: str) -> str:
638638
)
639639

640640
def quote_default_value(self, value: str) -> str:
641+
"""
642+
Return a SQL-safe representation of a column default value.
643+
644+
Already-quoted string literals and the SQLite special keywords
645+
``CURRENT_TIME``, ``CURRENT_DATE``, and ``CURRENT_TIMESTAMP`` are
646+
returned unchanged. Expressions that end in ``)`` are wrapped in
647+
parentheses. All other values are passed through :meth:`quote`.
648+
649+
:param value: The default value to format.
650+
"""
641651
if any(
642652
[
643653
str(value).startswith("'") and str(value).endswith("'"),
@@ -735,6 +745,12 @@ def supports_strict(self) -> bool:
735745

736746
@property
737747
def supports_on_conflict(self) -> bool:
748+
"""
749+
Return ``True`` if the connected SQLite version supports upserts via
750+
``INSERT INTO ... ON CONFLICT DO UPDATE`` (requires SQLite 3.24+).
751+
752+
The result is cached on the instance after the first call.
753+
"""
738754
# SQLite's upsert is implemented as INSERT INTO ... ON CONFLICT DO ...
739755
if not hasattr(self, "_supports_on_conflict"):
740756
table_name = "t{}".format(secrets.token_hex(16))
@@ -839,6 +855,12 @@ def reset_counts(self) -> None:
839855
def execute_returning_dicts(
840856
self, sql: str, params: Optional[Union[Sequence, Dict[str, Any]]] = None
841857
) -> List[dict]:
858+
"""
859+
Execute a SQL query and return the results as a list of dictionaries.
860+
861+
:param sql: SQL query to execute.
862+
:param params: Optional parameters to pass to the query.
863+
"""
842864
return list(self.query(sql, params))
843865

844866
def resolve_foreign_keys(
@@ -1396,6 +1418,13 @@ def count_where(
13961418
return self.db.execute(sql, where_args or []).fetchone()[0]
13971419

13981420
def execute_count(self) -> int:
1421+
"""
1422+
Return the total number of rows in this table or view.
1423+
1424+
.. deprecated::
1425+
Use :meth:`count_where` or the :attr:`count` property instead.
1426+
Kept for backwards compatibility only.
1427+
"""
13991428
# Backwards compatibility, see https://github.com/simonw/sqlite-utils/issues/305#issuecomment-890713185
14001429
return self.count_where()
14011430

0 commit comments

Comments
 (0)