{"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1422681850", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1422681850, "node_id": "IC_kwDOCGYnMM5UzGb6", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-08T14:25:50Z", "updated_at": "2023-02-08T14:29:09Z", "author_association": "NONE", "body": "I live the patch here for others:\r\n\r\n_original code_\r\n```shell\r\n$ which sqlite-utils | xargs cat\r\n```\r\n```python\r\n#!/usr/bin/python3\r\n# -*- coding: utf-8 -*-\r\nimport re\r\nimport sys\r\nfrom sqlite_utils.cli import cli\r\n\r\n\r\nif __name__ == '__main__':\r\n sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])\r\n sys.exit(cli())\r\n```\r\n\r\n_patched/sqlite-utils.py_\r\n```python\r\n#!/usr/bin/python3\r\n# -*- coding: utf-8 -*-\r\nimport re\r\nimport sys\r\nfrom sqlite_utils.cli import cli\r\n\r\n# New imports\r\nfrom unittest.mock import patch\r\nfrom sqlite_utils.cli import VALID_COLUMN_TYPES\r\n\r\n\r\nif __name__ == '__main__':\r\n # Choices of the option `--type`\r\n cli.commands['transform'].params[2].type.types[1].choices.append('DATETIME')\r\n\r\n # The dicts has to be extended with a new type\r\n with patch.dict('sqlite_utils.db.COLUMN_TYPE_MAPPING', {'DATETIME': 'DATETIME'}),\\\r\n patch('sqlite_utils.cli.VALID_COLUMN_TYPES', VALID_COLUMN_TYPES + (\"DATETIME\", )):\r\n\r\n # Command is unchanged\r\n sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])\r\n sys.exit(cli())\r\n```\r\n\r\nAnd now it's working\r\n```bash\r\n$ sqlite-utils schema events.sqlite cards.chunk.get\r\nCREATE TABLE \"cards.chunk.get\" (\r\n [id] INTEGER PRIMARY KEY NOT NULL,\r\n [timestamp] TEXT,\r\n)\r\n\r\n$ python patched/sqlite-utils.py transform events.sqlite cards.chunk.get --type timestamp DATETIME\r\n\r\n$ sqlite-utils schema events.sqlite cards.chunk.get\r\nCREATE TABLE \"cards.chunk.get\" (\r\n [id] INTEGER PRIMARY KEY NOT NULL,\r\n [timestamp] DATETIME,\r\n)\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": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1421177666", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1421177666, "node_id": "IC_kwDOCGYnMM5UtXNC", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-07T17:39:00Z", "updated_at": "2023-02-07T17:39:00Z", "author_association": "NONE", "body": "> lets users make schema changes, so it's important to me that the tool work in a non-surprising way -- if you ask for a column of type X, you should get type X. If the column or table previously had CHECK constraints, they shouldn't be silently removed\r\n\r\nI've got your concern. Let's see if we will be replied on it and i'll close the issue some later.\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1421055590", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1421055590, "node_id": "IC_kwDOCGYnMM5Us5Zm", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-07T16:25:31Z", "updated_at": "2023-02-07T16:25:31Z", "author_association": "NONE", "body": "> Ah, it looks like that is controlled by this dict: https://github.com/simonw/sqlite-utils/blob/main/sqlite_utils/db.py#L178\r\n> \r\n> I suspect you could overwrite the datetime entry to achieve what you want\r\n\r\nAnd thank you for pointing me to it. At least, i can make a monkey patch for my need...", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1421052195", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1421052195, "node_id": "IC_kwDOCGYnMM5Us4kj", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-07T16:23:17Z", "updated_at": "2023-02-07T16:23:57Z", "author_association": "NONE", "body": "Isn't your suggestion too fundamental for the utility?\r\n\r\nThe bigger flexibility, the bigger complexity. Your idea make sense defenitely, but how often do you make schema changes? And how many people could benefit from it, what do you think?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1421022917", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1421022917, "node_id": "IC_kwDOCGYnMM5UsxbF", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-07T16:06:03Z", "updated_at": "2023-02-07T16:08:58Z", "author_association": "NONE", "body": "> Do you see a way to enable it without affecting existing users or bumping the major version number?\r\n\r\nI don't see a clean solution, only extending code with a side variable that tells us we want to apply advanced types instead of basic.\r\n\r\nit could be a similiar command like `tranform-v2 --type column DATETIME` or a cli option `transform --adv-type column DATETIME` along with a dict that contains the advanced types. Then with knowledge that we run an advanced command we take that dictionary somehow, we can wrap the current and new dictionaries by a superdict and work with it everywhere according to the knowledge. This way shouldn't affect users who are using the previous lib versions and it have to be merged in the next major one.\r\n\r\nBut this way looks a bad design, too messy.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1420966995", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1420966995, "node_id": "IC_kwDOCGYnMM5UsjxT", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-07T15:29:28Z", "updated_at": "2023-02-07T15:29:28Z", "author_association": "NONE", "body": "I could, of course.\r\n\r\nDoest it worth bringing such the improvement to the library?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1420496447", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1420496447, "node_id": "IC_kwDOCGYnMM5Uqw4_", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-07T09:57:38Z", "updated_at": "2023-02-07T09:57:38Z", "author_association": "NONE", "body": "> That said, it looks like the check is only enforced at the CLI level. If you use the API directly, I think it'll work.\r\n\r\nIt works, but a column becomes `TEXT`\r\n\r\n```python\r\nIn [1]: import sqlite_utils\r\nIn [2]: db = sqlite_utils.Database('events.sqlite')\r\nIn [3]: table = db['cards.chunk.get']\r\nIn [4]: table.columns_dict\r\nOut[4]:\r\n{'id': int,\r\n 'timestamp': float,\r\n 'data_chunk_number': int,\r\n 'user_id': str,\r\n 'meta_duplication_source_id': int,\r\n 'context_sort_attribute': str,\r\n 'context_sort_order': str}\r\n\r\nIn [5]: from datetime import datetime\r\nIn [7]: table.transform(types={'timestamp': datetime})\r\nIn [8]: table.columns_dict\r\nOut[8]:\r\n{'id': int,\r\n 'timestamp': str,\r\n 'data_chunk_number': int,\r\n 'user_id': str,\r\n 'meta_duplication_source_id': int,\r\n 'context_sort_attribute': str,\r\n 'context_sort_order': str}\r\n```\r\n\r\n```bash\r\n\u276f sqlite-utils schema events.sqlite cards.chunk.get\r\nCREATE TABLE \"cards.chunk.get\" (\r\n [id] INTEGER PRIMARY KEY NOT NULL,\r\n [timestamp] TEXT,\r\n ...\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": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/524#issuecomment-1419390560", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/524", "id": 1419390560, "node_id": "IC_kwDOCGYnMM5Umi5g", "user": {"value": 21095447, "label": "4l1fe"}, "created_at": "2023-02-06T16:43:47Z", "updated_at": "2023-02-06T16:43:47Z", "author_association": "NONE", "body": "> SQLite doesn't have a native `DATETIME` type. It stores dates internally as strings and then has [functions](https://www.sqlite.org/lang_datefunc.html) to work with date-like strings. Yes it's weird.\r\n\r\nThat's correct. But my issue is about the application level libraries that, i suppose, have better data understanding if see a specific type such as `DATETIME`. \r\n\r\nI'm writing data with **dataset** i've mentioned. The lib changes its behavior depending on a type. I saw different behavior with types `DATETIME, FLOAT, TEXT`. Dataset, for their part, is built upon Sqlalchemy, you know what it is.\r\n\r\nTo be honest, i didn't dive into the details of why the behavior changes, but when i altered manually by other util a type of column to `DATETIME` things got back to normal.\r\n\r\nOn the matter, can i achieve it with Sqlite Utils at the moment?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1572766460, "label": "Transformation type `--type DATETIME`"}, "performed_via_github_app": null}