mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
register_function(name=...) argument, closes #458
This commit is contained in:
parent
bfbe69646e
commit
1491b66dd7
3 changed files with 30 additions and 6 deletions
|
|
@ -2513,6 +2513,16 @@ You can also use the method as a function decorator like so:
|
|||
|
||||
print(db.execute('select reverse_string("hello")').fetchone()[0])
|
||||
|
||||
By default, the name of the Python function will be used as the name of the SQL function. You can customize this with the ``name=`` keyword argument:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@db.register_function(name="rev")
|
||||
def reverse_string(s):
|
||||
return "".join(reversed(list(s)))
|
||||
|
||||
print(db.execute('select rev("hello")').fetchone()[0])
|
||||
|
||||
Python 3.8 added the ability to register `deterministic SQLite functions <https://sqlite.org/deterministic.html>`__, allowing you to indicate that a function will return the exact same result for any given inputs and hence allowing SQLite to apply some performance optimizations. You can mark a function as deterministic using ``deterministic=True``, like this:
|
||||
|
||||
.. code-block:: python
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue