{"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991405755", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991405755, "node_id": "IC_kwDOCGYnMM47F6a7", "user": {"value": 536941, "label": "fgregg"}, "created_at": "2021-12-11T01:38:29Z", "updated_at": "2021-12-11T01:38:29Z", "author_association": "CONTRIBUTOR", "body": "wow! that's awesome! thanks so much, @simonw!", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991400016", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991400016, "node_id": "IC_kwDOCGYnMM47F5BQ", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-11T01:10:52Z", "updated_at": "2021-12-11T01:11:02Z", "author_association": "OWNER", "body": "This won't be in a release for a little while, but you can install it to try it out using:\r\n\r\n pip install https://github.com/simonw/sqlite-utils/archive/ee13f98c2c.zip", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991399782", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991399782, "node_id": "IC_kwDOCGYnMM47F49m", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-11T01:09:37Z", "updated_at": "2021-12-11T01:09:37Z", "author_association": "OWNER", "body": "OK, this is implemented. Updated documentation is here: https://sqlite-utils.datasette.io/en/latest/cli.html#converting-data-in-columns", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991381679", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991381679, "node_id": "IC_kwDOCGYnMM47F0iv", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-10T23:58:43Z", "updated_at": "2021-12-10T23:59:35Z", "author_association": "OWNER", "body": "I think the fix for this is to change the rules about what code is accepted in both the `-` mode and the literal code string mode: you can pass in a Python expression, OR a fragment that gets turned into a function, OR code that implements its own `def convert(value)` function. So this would work too:\r\n```sh\r\nsqlite-utils convert my.db mytable col1 '\r\ndef convert(value):\r\n return value.upper()\r\n'\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991381281", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991381281, "node_id": "IC_kwDOCGYnMM47F0ch", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-10T23:57:26Z", "updated_at": "2021-12-10T23:57:26Z", "author_association": "OWNER", "body": "My first attempt at building this looked a little bit strange, because you would end up having a file like this `convert.py`:\r\n\r\n```\r\nvalue = value.upper()\r\nreturn value\r\n```\r\nWhich gets used like this:\r\n\r\n cat convert.py | sqlite-utils convert my.db mytable col1 -\r\n\r\nBut... that `convert.py` code isn't actually valid Python - it's a weird thing where you have a partial snippet of Python code that gets wrapped in a function automatically.\r\n\r\nIt would be better if you could write `convert.py` as a valid Python file with a function in it, something like this:\r\n```python\r\ndef convert(value):\r\n value = value.upper()\r\n return value\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991378346", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991378346, "node_id": "IC_kwDOCGYnMM47Fzuq", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-10T23:48:28Z", "updated_at": "2021-12-10T23:48:28Z", "author_association": "OWNER", "body": "One option: allow `CODE` to be a special value of `-` which means \"read from standard input\". It's a tiny bit of a hack but I think it would work here.\r\n\r\nIf you wanted to replace a column entirely with hyphens you would still be able to do this:\r\n\r\n sqlite-utils convert my.db mytable col1 '\"-\"'", "reactions": "{\"total_count\": 1, \"+1\": 1, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991377288", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991377288, "node_id": "IC_kwDOCGYnMM47FzeI", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-10T23:45:53Z", "updated_at": "2021-12-10T23:45:53Z", "author_association": "OWNER", "body": "One challenge here: the current signature looks like this:\r\n```\r\n% sqlite-utils convert --help\r\nUsage: sqlite-utils convert [OPTIONS] DB_PATH TABLE COLUMNS... CODE\r\n```\r\n`CODE` is a positional argument which comes last - and since `COLUMNS` can be one or more items, making `CODE` optional isn't easy.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/353#issuecomment-991376639", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/353", "id": 991376639, "node_id": "IC_kwDOCGYnMM47FzT_", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-10T23:43:45Z", "updated_at": "2021-12-10T23:43:45Z", "author_association": "OWNER", "body": "There's a very non-obvious workaround for this at the moment. You can save your code in e.g. a file called` transform.py` - my test one looks like this:\r\n```python\r\ndef upper(value):\r\n return value.upper()\r\n```\r\nThen you can run the following to import and use that function:\r\n\r\n`PYTHONPATH=. sqlite-utils convert fixtures.db roadside_attractions name 'transform.upper(value)' --import transform`\r\n\r\nThat `PYTHONPATH=. bit is necessary because otherwise the script won't look in the current directory for that `transform.py` module.\r\n\r\nNow that I've written this down, it's obviously bad! I think your suggestion here is a good idea.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1077102934, "label": "Allow passing a file of code to \"sqlite-utils convert\""}, "performed_via_github_app": null}