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
|
||||
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)
|
||||
|
@ -165,7 +165,7 @@ class TableView(DataView):
|
|||
).first()
|
||||
return Response.json(
|
||||
{
|
||||
"row": dict(new_row),
|
||||
"inserted_row": dict(new_row),
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
@ -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"
|
||||
|
|
Ładowanie…
Reference in New Issue