Skip to content

Commit

Permalink
Slight tweak to insert row API design, refs #1851
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Oct 27, 2022
1 parent 6958e21 commit a516080
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ async def table_post(self, request, database_name, table_name):
# TODO: handle form-encoded data
raise BadRequest("Must send JSON data")
data = json.loads(await request.post_body())
if "row" not in data:
raise BadRequest('Must send "row" data')
row = data["row"]
if "insert" not in data:
raise BadRequest('Must send a "insert" key containing a dictionary')
row = data["insert"]
if not isinstance(row, dict):
raise BadRequest("row must be a dictionary")
raise BadRequest("insert must be a dictionary")
# Verify all columns exist
columns = await db.table_columns(table_name)
pks = await db.primary_keys(table_name)
Expand Down Expand Up @@ -165,7 +165,7 @@ async def table_post(self, request, database_name, table_name):
).first()
return Response.json(
{
"row": dict(new_row),
"inserted_row": dict(new_row),
},
status=201,
)
Expand Down
4 changes: 2 additions & 2 deletions docs/json_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ This requires the :ref:`permissions_insert_row` permission.
Content-Type: application/json
Authorization: Bearer dstok_<rest-of-token>
{
"row": {
"insert": {
"column1": "value1",
"column2": "value2"
}
Expand All @@ -487,7 +487,7 @@ If successful, this will return a ``201`` status code and the newly inserted row
.. code-block:: json
{
"row": {
"inserted_row": {
"id": 1,
"column1": "value1",
"column2": "value2"
Expand Down

0 comments on commit a516080

Please sign in to comment.