home / github / issue_comments

Menu
  • GraphQL API

issue_comments: 1336094562

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/datasette/issues/1878#issuecomment-1336094562 https://api.github.com/repos/simonw/datasette/issues/1878 1336094562 IC_kwDOBm6k_c5Poy9i 9599 2022-12-03T06:27:50Z 2022-12-03T06:29:06Z OWNER This adds it to the API explorer: ```diff diff --git a/datasette/views/special.py b/datasette/views/special.py index 1f84b094..1b4a9d3c 100644 --- a/datasette/views/special.py +++ b/datasette/views/special.py @@ -316,21 +316,37 @@ class ApiExplorerView(BaseView): request.actor, "insert-row", (name, table) ): pks = await db.primary_keys(table) - table_links.append( - { - "path": self.ds.urls.table(name, table) + "/-/insert", - "method": "POST", - "label": "Insert rows into {}".format(table), - "json": { - "rows": [ - { - column: None - for column in await db.table_columns(table) - if column not in pks - } - ] + table_links.extend( + [ + { + "path": self.ds.urls.table(name, table) + "/-/insert", + "method": "POST", + "label": "Insert rows into {}".format(table), + "json": { + "rows": [ + { + column: None + for column in await db.table_columns(table) + if column not in pks + } + ] + }, }, - } + { + "path": self.ds.urls.table(name, table) + "/-/upsert", + "method": "POST", + "label": "Upsert rows into {}".format(table), + "json": { + "rows": [ + { + column: None + for column in await db.table_columns(table) + if column not in pks + } + ] + }, + }, + ] ) if await self.ds.permission_allowed( request.actor, "drop-table", (name, table) ``` Except it doesn't quite, because the example JSON this generates is invalid as it does not include the primary key column. (Made me notice that the way example columns are created for `/-/insert` will fail for tables that don't have an auto-incrementing primary key) {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1432013704  
Powered by Datasette · Queries took 0.924ms