kopia lustrzana https://github.com/simonw/datasette
Slight tweak to insert row API design, refs #1851
https://github.com/simonw/datasette/issues/1851#issuecomment-1292997608pull/1912/head
rodzic
6958e21b5c
commit
a51608090b
|
@ -131,11 +131,11 @@ class TableView(DataView):
|
||||||
# TODO: handle form-encoded data
|
# TODO: handle form-encoded data
|
||||||
raise BadRequest("Must send JSON data")
|
raise BadRequest("Must send JSON data")
|
||||||
data = json.loads(await request.post_body())
|
data = json.loads(await request.post_body())
|
||||||
if "row" not in data:
|
if "insert" not in data:
|
||||||
raise BadRequest('Must send "row" data')
|
raise BadRequest('Must send a "insert" key containing a dictionary')
|
||||||
row = data["row"]
|
row = data["insert"]
|
||||||
if not isinstance(row, dict):
|
if not isinstance(row, dict):
|
||||||
raise BadRequest("row must be a dictionary")
|
raise BadRequest("insert must be a dictionary")
|
||||||
# Verify all columns exist
|
# Verify all columns exist
|
||||||
columns = await db.table_columns(table_name)
|
columns = await db.table_columns(table_name)
|
||||||
pks = await db.primary_keys(table_name)
|
pks = await db.primary_keys(table_name)
|
||||||
|
@ -165,7 +165,7 @@ class TableView(DataView):
|
||||||
).first()
|
).first()
|
||||||
return Response.json(
|
return Response.json(
|
||||||
{
|
{
|
||||||
"row": dict(new_row),
|
"inserted_row": dict(new_row),
|
||||||
},
|
},
|
||||||
status=201,
|
status=201,
|
||||||
)
|
)
|
||||||
|
|
|
@ -476,7 +476,7 @@ This requires the :ref:`permissions_insert_row` permission.
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: Bearer dstok_<rest-of-token>
|
Authorization: Bearer dstok_<rest-of-token>
|
||||||
{
|
{
|
||||||
"row": {
|
"insert": {
|
||||||
"column1": "value1",
|
"column1": "value1",
|
||||||
"column2": "value2"
|
"column2": "value2"
|
||||||
}
|
}
|
||||||
|
@ -487,7 +487,7 @@ If successful, this will return a ``201`` status code and the newly inserted row
|
||||||
.. code-block:: json
|
.. code-block:: json
|
||||||
|
|
||||||
{
|
{
|
||||||
"row": {
|
"inserted_row": {
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"column1": "value1",
|
"column1": "value1",
|
||||||
"column2": "value2"
|
"column2": "value2"
|
||||||
|
|
Ładowanie…
Reference in New Issue