From aa300942bfcba0bd788951db0b9070cf291c193a Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 7 Jul 2026 18:03:25 -0700 Subject: [PATCH] Update sqlite-utils convert --help, refs #686 --- docs/cli-reference.rst | 7 +++++-- sqlite_utils/cli.py | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/cli-reference.rst b/docs/cli-reference.rst index c232881..105b19a 100644 --- a/docs/cli-reference.rst +++ b/docs/cli-reference.rst @@ -621,6 +621,11 @@ See :ref:`cli_convert`. "value" is a variable with the column value to be converted. + CODE can also be a reference to a callable that takes the value, for example: + + sqlite-utils convert my.db mytable date r.parsedate + sqlite-utils convert my.db mytable data json.loads --import json + Use "-" for CODE to read Python code from standard input. The following common operations are available as recipe functions: @@ -634,7 +639,6 @@ See :ref:`cli_convert`. errors: 'Optional[object]' = None) -> 'Optional[str]' Parse a date and convert it to ISO date format: yyyy-mm-dd - - dayfirst=True: treat xx as the day in xx/yy/zz - yearfirst=True: treat xx as the year in xx/yy/zz - errors=r.IGNORE to ignore values that cannot be parsed @@ -644,7 +648,6 @@ See :ref:`cli_convert`. False, errors: 'Optional[object]' = None) -> 'Optional[str]' Parse a datetime and convert it to ISO datetime format: yyyy-mm-ddTHH:MM:SS - - dayfirst=True: treat xx as the day in xx/yy/zz - yearfirst=True: treat xx as the year in xx/yy/zz - errors=r.IGNORE to ignore values that cannot be parsed diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index edf1634..318b208 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -3054,6 +3054,12 @@ def _generate_convert_help(): "value" is a variable with the column value to be converted. + CODE can also be a reference to a callable that takes the value, for example: + + \b + sqlite-utils convert my.db mytable date r.parsedate + sqlite-utils convert my.db mytable data json.loads --import json + Use "-" for CODE to read Python code from standard input. The following common operations are available as recipe functions: @@ -3067,8 +3073,9 @@ def _generate_convert_help(): ] for name in recipe_names: fn = getattr(recipes, name) + doc = textwrap.dedent(fn.__doc__.rstrip()).replace("\b\n", "") help += "\n\nr.{}{}\n\n\b{}".format( - name, str(inspect.signature(fn)), textwrap.dedent(fn.__doc__.rstrip()) + name, str(inspect.signature(fn)), doc ) help += "\n\n" help += textwrap.dedent("""