question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sqlite-utils query --functions mechanism for registering extra functions

See original GitHub issue

It would be really cool if you could register additional custom SQL functions for use with the sqlite-utils query command - something like this:

sqlite-utils data.db 'update images set domain = extract_domain(url)' --functions '
from urllib.parse import urlparse

def extract_domain(url):
    return urlparse(url).netloc
'

Every function defined in that code block would be registered with the connection, unless the name began with an underscore.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
simonwcommented, Aug 27, 2022

Testing bulk --functions:

% sqlite-utils create-table chickens.db chickens id integer name text name_upper text 
% echo 'id,name
1,Blue
2,Snowy
3,Azi
4,Lila
5,Suna
6,Cardi' | sqlite-utils bulk chickens.db '
insert into chickens (id, name, name_upper) values (:id, :name, myupper(:name))
' - --functions '
def myupper(s):
    return s.upper()
' --csv
% sqlite-utils rows chickens.db chickens
[{"id": 1, "name": "Blue", "name_upper": "BLUE"},
 {"id": 2, "name": "Snowy", "name_upper": "SNOWY"},
 {"id": 3, "name": "Azi", "name_upper": "AZI"},
 {"id": 4, "name": "Lila", "name_upper": "LILA"},
 {"id": 5, "name": "Suna", "name_upper": "SUNA"},
 {"id": 6, "name": "Cardi", "name_upper": "CARDI"}]
0reactions
simonwcommented, Sep 7, 2022

Is it still nfortunately slow and tricky when playing with floats ?

Not sure what you mean here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

sqlite_utils Python library - sqlite-utils - Datasette
SQLite supports registering custom SQL functions written in Python. The db.register_function() method lets you register these functions, and keeps track of ...
Read more >
sqlite-utils documentation - Datasette
Python utility functions for manipulating SQLite databases. This library and command-line utility helps create SQLite databases from an ...
Read more >
sqlite-utils documentation
Python utility functions for manipulating SQLite databases. This library and command-line utility helps create SQLite databases from an ...
Read more >
sqlite-utils command-line tool
You can use the --functions option to pass a block of Python code that defines additional functions which can then be called by...
Read more >
sqlite-utils documentation - Datasette
Python utility functions for manipulating SQLite databases. This library and command-line utility helps create SQLite databases from an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found