sqlite-utils
sqlite-utils copied to clipboard
Idea: conversions= could take Python functions
Right now you use conversions= like this:
db["example"].insert({
"name": "The Bigfoot Discovery Museum"
}, conversions={"name": "upper(?)"})
How about if you could optionally provide a Python function (or a lambda) like this?
db["example"].insert({
"name": "The Bigfoot Discovery Museum"
}, conversions={"name": lambda s: s.upper()})
This would work by creating a random name for that function, registering it (similar to #162), executing the SQL and then un-registering the custom function at the end.
This would apply to .transform() in #114 too.
This could even be exposed as a feature of the CLI tool - similar to how sqlite-transform works: https://github.com/simonw/sqlite-transform
$ sqlite-transform lambda my.db mytable mycolumn --code='str(value).upper()'
Maybe sqlite-utils should absorb all of the functionality from sqlite-transform - having two separate tools doesn't necessarily make sense.
sqlite-utils convert my.db mytable mycolumn could become the new sqlite-transform. The sub-command could take --code but could also take --parsedate and --parsedatetime options.
Maybe
sqlite-utilsshould absorb all of the functionality fromsqlite-transform- having two separate tools doesn't necessarily make sense.
I implemented that in:
- #251