{"html_url": "https://github.com/simonw/sqlite-utils/issues/24#issuecomment-501572149", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/24", "id": 501572149, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTU3MjE0OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T06:47:17Z", "updated_at": "2019-06-13T06:47:17Z", "author_association": "OWNER", "body": "@IgnoredAmbience this is now shipped in sqlite-utils 1.2 - documentation here:\r\n\r\n* https://sqlite-utils.readthedocs.io/en/latest/python-api.html#python-api-defaults-not-null\r\n* https://sqlite-utils.readthedocs.io/en/latest/cli.html#cli-defaults-not-null", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449818897, "label": "Additional Column Constraints?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/24#issuecomment-501516028", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/24", "id": 501516028, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTUxNjAyOA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T01:42:36Z", "updated_at": "2019-06-13T01:42:36Z", "author_association": "OWNER", "body": "Maybe it's time to create a `sqlite-utils create-table` command here too, rather than forcing people to create tables only by inserting example data.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449818897, "label": "Additional Column Constraints?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/24#issuecomment-501515609", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/24", "id": 501515609, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTUxNTYwOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T01:40:12Z", "updated_at": "2019-06-13T01:40:47Z", "author_association": "OWNER", "body": "But what to do for creating a table?\r\n\r\nFor the Python function I could do this:\r\n```python\r\ndb[\"cats\"].create({\r\n \"id\": int,\r\n \"name\": str,\r\n \"score\": int, \r\n \"weight\": float,\r\n}, pk=\"id\", not_null={\"weight\"}, defaults={\"score\": 1})\r\n```\r\n\r\nThe CLI tool only every creates tables as a side-effect of a `sqlite-utils insert` or `sqlite-utils upsert`. I can have them accept optional arguments, `--not-null colname` and `--default colname value`:\r\n```\r\necho '{\"name\": \"Cleo\", \"age\": 4, \"score\": 2}' | \\\r\n sqlite-utils insert dogs.db dogs - \\\r\n --not-null age \\\r\n --not-null name \\\r\n --default score 1\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449818897, "label": "Additional Column Constraints?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/24#issuecomment-501514575", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/24", "id": 501514575, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTUxNDU3NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T01:34:55Z", "updated_at": "2019-06-13T01:34:55Z", "author_association": "OWNER", "body": "Since you can't have one without the other, I'm going with `--not-null-default=` and `not_null_default=` for the add column versions of this.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449818897, "label": "Additional Column Constraints?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/24#issuecomment-501509642", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/24", "id": 501509642, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTUwOTY0Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T01:06:09Z", "updated_at": "2019-06-13T01:06:09Z", "author_association": "OWNER", "body": "Hmm... we need the ability to pass `--not-null` when we are creating a table as well.\r\n\r\nIf you attempt to add `NOT NULL` to a column after a table has first been created you get this error:\r\n\r\n```sqlite3.OperationalError: Cannot add a NOT NULL column with default value NULL```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449818897, "label": "Additional Column Constraints?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/24#issuecomment-499603495", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/24", "id": 499603495, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5OTYwMzQ5NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-06T18:02:20Z", "updated_at": "2019-06-06T18:02:20Z", "author_association": "OWNER", "body": "This seems reasonable. It could look like this:\r\n\r\n```python\r\ndb[\"dogs\"].add_column(\"instagram\", str, not_null=True)\r\ndb[\"dogs\"].add_column(\"is_good_dog\", bool, default=True)\r\n```\r\nAnd this:\r\n```bash\r\n$ sqlite-utils add-column mydb.db dogs instagram --not-null\r\n$ sqlite-utils add-column mydb.db dogs is_good_dog integer --default=1\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": 449818897, "label": "Additional Column Constraints?"}, "performed_via_github_app": null}