{"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1298919552", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1298919552, "node_id": "IC_kwDOBm6k_c5Na_CA", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-11-01T18:11:27Z", "updated_at": "2022-11-01T18:11:27Z", "author_association": "OWNER", "body": "I forgot to document `ignore` and `replace`. Also I need to add tests that cover:\r\n\r\n- Forgetting to include a primary key on a non-autoincrement table\r\n- Compound primary keys\r\n- Rowid only tables with and without rowid specified\r\n\r\nI think my validation logic here will get caught out by the fact that `rowid` does not show up as a valid column name: https://github.com/simonw/datasette/blob/9bec7c38eb93cde5afb16df9bdd96aea2a5b0459/datasette/views/table.py#L1151-L1160\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1298905135", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1298905135, "node_id": "IC_kwDOBm6k_c5Na7gv", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-11-01T17:59:59Z", "updated_at": "2022-11-01T17:59:59Z", "author_association": "OWNER", "body": "It's a bit surprising that you can send `\"ignore\": true, \"return_rows\": true` and the returned `\"inserted\"` key will list rows that were NOT inserted (since they were ignored).\r\n\r\nThree options:\r\n\r\n1. Ignore that and document it\r\n2. Fix it so `\"inserted\"` only returns rows that were actually inserted (bit tricky)\r\n3. Change the name of `\"inserted\"` to something else\r\n\r\nI'm picking 3 - I'm going to change it to be called `\"rows\"` instead.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1298885451", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1298885451, "node_id": "IC_kwDOBm6k_c5Na2tL", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-11-01T17:42:20Z", "updated_at": "2022-11-01T17:42:20Z", "author_association": "OWNER", "body": "Design decision:\r\n```json\r\n{\r\n \"rows\": [{\"id\": 1, \"title\": \"The title\"}],\r\n \"ignore\": true\r\n}\r\n```\r\nOr `\"replace\": true`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296343716", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296343716, "node_id": "IC_kwDOBm6k_c5NRKKk", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:24:55Z", "updated_at": "2022-10-30T20:24:55Z", "author_association": "OWNER", "body": "I think the key feature I need here is going to be the equivalent of `ignore=True` and `replace=True` for dealing with primary key collisions, see https://sqlite-utils.datasette.io/en/stable/reference.html#sqlite_utils.db.Table.insert", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296343317", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296343317, "node_id": "IC_kwDOBm6k_c5NRKEV", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:22:40Z", "updated_at": "2022-10-30T20:22:40Z", "author_association": "OWNER", "body": "So maybe they're not actually worth worrying about separately, because they are guaranteed to have a primary key set.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296343173", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296343173, "node_id": "IC_kwDOBm6k_c5NRKCF", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:21:54Z", "updated_at": "2022-10-30T20:22:20Z", "author_association": "OWNER", "body": "One last case to consider: `WITHOUT ROWID` tables.\r\n\r\nhttps://www.sqlite.org/withoutrowid.html\r\n\r\n> By default, every row in SQLite has a special column, usually called the \"[rowid](https://www.sqlite.org/lang_createtable.html#rowid)\", that uniquely identifies that row within the table. However if the phrase \"WITHOUT ROWID\" is added to the end of a [CREATE TABLE](https://www.sqlite.org/lang_createtable.html) statement, then the special \"rowid\" column is omitted. There are sometimes space and performance advantages to omitting the rowid.\r\n>\r\n> ...\r\n>\r\n> Every WITHOUT ROWID table must have a [PRIMARY KEY](https://www.sqlite.org/lang_createtable.html#primkeyconst). An error is raised if a CREATE TABLE statement with the WITHOUT ROWID clause lacks a PRIMARY KEY.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296343014", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296343014, "node_id": "IC_kwDOBm6k_c5NRJ_m", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:21:01Z", "updated_at": "2022-10-30T20:21:01Z", "author_association": "OWNER", "body": "Actually, for simplicity I'm going to say that you can always set the primary key, even for auto-incrementing primary key columns... but you cannot set it on pure `rowid` columns.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296342814", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296342814, "node_id": "IC_kwDOBm6k_c5NRJ8e", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:20:05Z", "updated_at": "2022-10-30T20:20:05Z", "author_association": "OWNER", "body": "Some notes on what Datasette does already\r\n\r\nhttps://latest.datasette.io/fixtures/tags.json?_shape=array returns:\r\n```json\r\n[\r\n {\r\n \"tag\": \"canine\"\r\n },\r\n {\r\n \"tag\": \"feline\"\r\n }\r\n]\r\n```\r\nThat table is defined [like this](https://latest.datasette.io/fixtures/tags):\r\n```sql\r\nCREATE TABLE tags (\r\n tag TEXT PRIMARY KEY\r\n);\r\n```\r\nHere's a `rowid` table with no explicit primary key: https://latest.datasette.io/fixtures/binary_data\r\n\r\nhttps://latest.datasette.io/fixtures/binary_data.json?_shape=array\r\n```json\r\n[\r\n {\r\n \"rowid\": 1,\r\n \"data\": {\r\n \"$base64\": true,\r\n \"encoded\": \"FRwCx60F/g==\"\r\n }\r\n },\r\n {\r\n \"rowid\": 2,\r\n \"data\": {\r\n \"$base64\": true,\r\n \"encoded\": \"FRwDx60F/g==\"\r\n }\r\n },\r\n {\r\n \"rowid\": 3,\r\n \"data\": null\r\n }\r\n]\r\n```\r\n```sql\r\nCREATE TABLE binary_data (\r\n data BLOB\r\n);\r\n```\r\nhttps://latest.datasette.io/fixtures/simple_primary_key has a text primary key:\r\n\r\nhttps://latest.datasette.io/fixtures/simple_primary_key.json?_shape=array\r\n```json\r\n[\r\n {\r\n \"id\": \"1\",\r\n \"content\": \"hello\"\r\n },\r\n {\r\n \"id\": \"2\",\r\n \"content\": \"world\"\r\n },\r\n {\r\n \"id\": \"3\",\r\n \"content\": \"\"\r\n },\r\n {\r\n \"id\": \"4\",\r\n \"content\": \"RENDER_CELL_DEMO\"\r\n },\r\n {\r\n \"id\": \"5\",\r\n \"content\": \"RENDER_CELL_ASYNC\"\r\n }\r\n]\r\n```\r\n```sql\r\nCREATE TABLE simple_primary_key (\r\n id varchar(30) primary key,\r\n content text\r\n);\r\n```\r\nhttps://latest.datasette.io/fixtures/compound_primary_key is a compound primary key.\r\n\r\nhttps://latest.datasette.io/fixtures/compound_primary_key.json?_shape=array\r\n```json\r\n[\r\n {\r\n \"pk1\": \"a\",\r\n \"pk2\": \"b\",\r\n \"content\": \"c\"\r\n },\r\n {\r\n \"pk1\": \"a/b\",\r\n \"pk2\": \".c-d\",\r\n \"content\": \"c\"\r\n }\r\n]\r\n```\r\n```sql\r\nCREATE TABLE compound_primary_key (\r\n pk1 varchar(30),\r\n pk2 varchar(30),\r\n content text,\r\n PRIMARY KEY (pk1, pk2)\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": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296341469", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296341469, "node_id": "IC_kwDOBm6k_c5NRJnd", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:13:50Z", "updated_at": "2022-10-30T20:13:50Z", "author_association": "OWNER", "body": "I checked and SQLite itself does allow you to set the `rowid` on that kind of table - it then increments from whatever you inserted:\r\n```\r\n% sqlite3 /tmp/t.db\r\nSQLite version 3.39.4 2022-09-07 20:51:41\r\nEnter \".help\" for usage hints.\r\nsqlite> create table docs (title text);\r\nsqlite> insert into docs (title) values ('one');\r\nsqlite> select rowid, title from docs;\r\n1|one\r\nsqlite> insert into docs (rowid, title) values (3, 'three');\r\nsqlite> select rowid, title from docs;\r\n1|one\r\n3|three\r\nsqlite> insert into docs (title) values ('another');\r\nsqlite> select rowid, title from docs;\r\n1|one\r\n3|three\r\n4|another\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296341055", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296341055, "node_id": "IC_kwDOBm6k_c5NRJg_", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T20:11:47Z", "updated_at": "2022-10-30T20:12:30Z", "author_association": "OWNER", "body": "If a table has an auto-incrementing primary key, should you be allowed to insert records with an explicit key into it?\r\n\r\nI'm torn on this one. It's something you can do with direct database access, but it's something I very rarely want to do.\r\n\r\nI'm inclined to disallow it and say that if you want that you can get it using a writable canned query instead.\r\n\r\nLikewise, I'm not going to provide a way to set the `rowid` explicitly on a freshly inserted row.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1873#issuecomment-1296131681", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1873", "id": 1296131681, "node_id": "IC_kwDOBm6k_c5NQWZh", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-10-30T06:27:12Z", "updated_at": "2022-10-30T06:27:12Z", "author_association": "OWNER", "body": "Relevant TODO: https://github.com/simonw/datasette/blob/c35859ae3df163406f1a1895ccf9803e933b2d8e/datasette/views/table.py#L1131-L1135", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1428630253, "label": "Ensure insert API has good tests for rowid and compound primark key tables"}, "performed_via_github_app": null}