home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1314620086

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/1875#issuecomment-1314620086 https://api.github.com/repos/simonw/datasette/issues/1875 1314620086 IC_kwDOBm6k_c5OW4K2 9599 2022-11-15T01:09:56Z 2022-11-15T01:09:56Z OWNER

Rough initial prototype: ```diff diff --git a/datasette/views/table.py b/datasette/views/table.py index 8b987221..518ac578 100644 --- a/datasette/views/table.py +++ b/datasette/views/table.py @@ -1103,19 +1103,30 @@ class TableInsertView(BaseView): except json.JSONDecodeError as e: return _errors(["Invalid JSON: {}".format(e)]) if not isinstance(data, dict): - return _errors(["JSON must be a dictionary"]) + return _errors([{"detail": "JSON must be a dictionary", "pointer": "#/"}]) keys = data.keys()

     # keys must contain "row" or "rows"
     if "row" not in keys and "rows" not in keys:
         return _errors(['JSON must have one or other of "row" or "rows"'])
     rows = []
  • was_single_row = False if "row" in keys: if "rows" in keys:
  • return _errors(['Cannot use "row" and "rows" at the same time'])
  • return _errors(
  • [
  • {
  • "detail": 'Cannot use "row" and "rows" at the same time',
  • "pointer": "#/row",
  • }
  • ]
  • )
  • was_single_row = True row = data["row"] if not isinstance(row, dict):
  • return _errors(['"row" must be a dictionary'])
  • return _errors(
  • [{"detail": '"row" must be a dictionary', "pointer": "#/row"}]
  • ) rows = [row] data["return"] = True else: @@ -1152,9 +1163,12 @@ class TableInsertView(BaseView): invalid_columns = set(row.keys()) - columns if invalid_columns: errors.append(
  • "Row {} has invalid columns: {}".format(
  • i, ", ".join(sorted(invalid_columns))
  • )
  • {
  • "detail": "Invalid columns: {}".format(
  • ", ".join(sorted(invalid_columns))
  • ),
  • "pointer": "#/blah/",
  • } ) if errors: return _errors(errors) ```
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
1430797211  
Powered by Datasette · Queries took 1.131ms · About: github-to-sqlite