diff --git a/datasette/views/table.py b/datasette/views/table.py index 8e6d8e4a..8b987221 100644 --- a/datasette/views/table.py +++ b/datasette/views/table.py @@ -1117,7 +1117,7 @@ class TableInsertView(BaseView): if not isinstance(row, dict): return _errors(['"row" must be a dictionary']) rows = [row] - data["return_rows"] = True + data["return"] = True else: rows = data["rows"] if not isinstance(rows, list): @@ -1137,7 +1137,7 @@ class TableInsertView(BaseView): extras = { key: value for key, value in data.items() if key not in ("row", "rows") } - valid_extras = {"return_rows", "ignore", "replace"} + valid_extras = {"return", "ignore", "replace"} invalid_extras = extras.keys() - valid_extras if invalid_extras: return _errors( @@ -1185,7 +1185,7 @@ class TableInsertView(BaseView): ignore = extras.get("ignore") replace = extras.get("replace") - should_return = bool(extras.get("return_rows", False)) + should_return = bool(extras.get("return", False)) # Insert rows def insert_rows(conn): table = sqlite_utils.Database(conn)[table_name] diff --git a/docs/json_api.rst b/docs/json_api.rst index 64a58ce3..842285cf 100644 --- a/docs/json_api.rst +++ b/docs/json_api.rst @@ -520,7 +520,7 @@ To insert multiple rows at a time, use the same API method but send a list of di If successful, this will return a ``201`` status code and an empty ``{}`` response body. -To return the newly inserted rows, add the ``"return_rows": true`` key to the request body: +To return the newly inserted rows, add the ``"return": true`` key to the request body: .. code-block:: json @@ -535,7 +535,7 @@ To return the newly inserted rows, add the ``"return_rows": true`` key to the re "column2": "value4" } ], - "return_rows": true + "return": true } This will return the same ``"rows"`` key as the single row example above. There is a small performance penalty for using this option. diff --git a/tests/test_api_write.py b/tests/test_api_write.py index 6ae3ac3f..5568279c 100644 --- a/tests/test_api_write.py +++ b/tests/test_api_write.py @@ -53,7 +53,7 @@ async def test_write_rows(ds_write, return_rows): token = write_token(ds_write) data = {"rows": [{"title": "Test {}".format(i), "score": 1.0} for i in range(20)]} if return_rows: - data["return_rows"] = True + data["return"] = True response = await ds_write.client.post( "/data/docs/-/insert", json=data, @@ -267,7 +267,7 @@ async def test_insert_ignore_replace( if replace: data["replace"] = True if should_return: - data["return_rows"] = True + data["return"] = True response = await ds_write.client.post( "/data/docs/-/insert", json=data, @@ -303,7 +303,7 @@ async def test_delete_row(ds_write, scenario): # Insert a row insert_response = await ds_write.client.post( "/data/docs/-/insert", - json={"row": {"title": "Row one", "score": 1.0}, "return_rows": True}, + json={"row": {"title": "Row one", "score": 1.0}, "return": True}, headers={ "Authorization": "Bearer {}".format(write_token(ds_write)), "Content-Type": "application/json",