-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing a file of code to "sqlite-utils convert" #353
Comments
There's a very non-obvious workaround for this at the moment. You can save your code in e.g. a file called def upper(value):
return value.upper() Then you can run the following to import and use that function:
That Now that I've written this down, it's obviously bad! I think your suggestion here is a good idea. |
One challenge here: the current signature looks like this:
|
One option: allow If you wanted to replace a column entirely with hyphens you would still be able to do this:
|
My first attempt at building this looked a little bit strange, because you would end up having a file like this
Which gets used like this:
But... that It would be better if you could write def convert(value):
value = value.upper()
return value |
I think the fix for this is to change the rules about what code is accepted in both the sqlite-utils convert my.db mytable col1 '
def convert(value):
return value.upper()
' |
OK, this is implemented. Updated documentation is here: https://sqlite-utils.datasette.io/en/latest/cli.html#converting-data-in-columns |
This won't be in a release for a little while, but you can install it to try it out using:
|
wow! that's awesome! thanks so much, @simonw! |
sqlite-utils is so nice, but the ergonomics of the multiline code in kind of tough. It's really hard (maybe impossible) to make the newlines play well with Makefiles.
it would be great to write your code fragment in a separate file and direct it into the sqlite-utils
either like
sqlite-utils convert my.db my_table my_column < custom_code.py
or
sqlite-utils convert my.db my_table my_column --custom-code=custom_code.py
Thanks, as ever, for these great tools!
The text was updated successfully, but these errors were encountered: