mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Also support def convert(value), closes #355
Plus added custom syntax error display
This commit is contained in:
parent
7a43af232e
commit
500a35ad4d
4 changed files with 91 additions and 47 deletions
19
docs/cli.rst
19
docs/cli.rst
|
|
@ -1029,17 +1029,24 @@ This supports nested imports as well, for example to use `ElementTree <https://d
|
|||
'xml.etree.ElementTree.fromstring(value).attrib["title"]' \
|
||||
--import=xml.etree.ElementTree
|
||||
|
||||
Use a CODE value of `-` to read from standard input:
|
||||
Your code will be automatically wrapped in a function, but you can also define a function called `convert(value)` which will be called, if available::
|
||||
|
||||
$ sqlite-utils convert content.db articles headline '
|
||||
def convert(value):
|
||||
return value.upper()'
|
||||
|
||||
Use a ``CODE`` value of ``-`` to read from standard input::
|
||||
|
||||
$ cat mycode.py | sqlite-utils convert content.db articles headline -
|
||||
|
||||
Where `mycode.py` contains a fragment of Python code that looks like this:
|
||||
Where ``mycode.py`` contains a fragment of Python code that looks like this:
|
||||
|
||||
```python
|
||||
return value.upper()
|
||||
```
|
||||
.. code-block:: python
|
||||
|
||||
The transformation will be applied to every row in the specified table. You can limit that to just rows that match a ``WHERE`` clause using ``--where``::
|
||||
def convert(value):
|
||||
return value.upper()
|
||||
|
||||
The conversion will be applied to every row in the specified table. You can limit that to just rows that match a ``WHERE`` clause using ``--where``::
|
||||
|
||||
$ sqlite-utils convert content.db articles headline 'value.upper()' \
|
||||
--where "headline like '%cat%'"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue