home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1239766987

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/sqlite-utils/issues/484#issuecomment-1239766987 https://api.github.com/repos/simonw/sqlite-utils/issues/484 1239766987 IC_kwDOCGYnMM5J5VfL 9599 2022-09-07T19:01:49Z 2022-09-07T19:01:49Z OWNER

OK with this: ```diff diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index c51b101..93d82a9 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -30,6 +30,7 @@ from .utils import ( Format, TypeTracker, ) +from . import recipes

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) @@ -3029,7 +3030,7 @@ def load_extensions(db, load_extension): def _register_functions(db, functions): # Register any Python functions as SQL functions: sqlite3.enable_callback_tracebacks(True) - globals = {} + globals = {"r": recipes, "recipes": recipes} try: exec(functions, globals) except SyntaxError as ex: @@ -3037,4 +3038,4 @@ def _register_functions(db, functions): # Register all callables in the locals dict: for name, value in globals.items(): if callable(value) and not name.startswith(""): - db.register_function(value, name=name) + db.register_function(value, name=name, ignore_defaults=True) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 27c46b0..1407d23 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -370,6 +370,7 @@ class Database: self, fn: Callable = None, deterministic: bool = False, + ignore_defaults: bool = False, replace: bool = False, name: Optional[str] = None, ): @@ -397,7 +398,10 @@ class Database:

     def register(fn):
         fn_name = name or fn.__name__
  • arity = len(inspect.signature(fn).parameters)
  • params = inspect.signature(fn).parameters
  • if ignore_defaults:
  • params = [p for p in params if params[p].default is inspect._empty]
  • arity = len(params) if not replace and (fn_name, arity) in self._registered_functions: return fn kwargs = {} I can now do this: % sqlite-utils memory --functions 'parsedate = r.parsedate' 'select parsedate("1st jan")' [{"parsedate(\"1st jan\")": "2022-01-01"}] ```
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
1363766973  
Powered by Datasette · Queries took 2.244ms · About: github-to-sqlite