Renamed return_rows to return in insert API

Refs https://github.com/simonw/datasette/issues/1866#issuecomment-1313128913
pull/1912/head
Simon Willison 2022-11-13 21:49:23 -08:00
rodzic 65521f03db
commit 264d0ab471
3 zmienionych plików z 8 dodań i 8 usunięć

Wyświetl plik

@ -1117,7 +1117,7 @@ class TableInsertView(BaseView):
if not isinstance(row, dict): if not isinstance(row, dict):
return _errors(['"row" must be a dictionary']) return _errors(['"row" must be a dictionary'])
rows = [row] rows = [row]
data["return_rows"] = True data["return"] = True
else: else:
rows = data["rows"] rows = data["rows"]
if not isinstance(rows, list): if not isinstance(rows, list):
@ -1137,7 +1137,7 @@ class TableInsertView(BaseView):
extras = { extras = {
key: value for key, value in data.items() if key not in ("row", "rows") 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 invalid_extras = extras.keys() - valid_extras
if invalid_extras: if invalid_extras:
return _errors( return _errors(
@ -1185,7 +1185,7 @@ class TableInsertView(BaseView):
ignore = extras.get("ignore") ignore = extras.get("ignore")
replace = extras.get("replace") replace = extras.get("replace")
should_return = bool(extras.get("return_rows", False)) should_return = bool(extras.get("return", False))
# Insert rows # Insert rows
def insert_rows(conn): def insert_rows(conn):
table = sqlite_utils.Database(conn)[table_name] table = sqlite_utils.Database(conn)[table_name]

Wyświetl plik

@ -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. 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 .. code-block:: json
@ -535,7 +535,7 @@ To return the newly inserted rows, add the ``"return_rows": true`` key to the re
"column2": "value4" "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. This will return the same ``"rows"`` key as the single row example above. There is a small performance penalty for using this option.

Wyświetl plik

@ -53,7 +53,7 @@ async def test_write_rows(ds_write, return_rows):
token = write_token(ds_write) token = write_token(ds_write)
data = {"rows": [{"title": "Test {}".format(i), "score": 1.0} for i in range(20)]} data = {"rows": [{"title": "Test {}".format(i), "score": 1.0} for i in range(20)]}
if return_rows: if return_rows:
data["return_rows"] = True data["return"] = True
response = await ds_write.client.post( response = await ds_write.client.post(
"/data/docs/-/insert", "/data/docs/-/insert",
json=data, json=data,
@ -267,7 +267,7 @@ async def test_insert_ignore_replace(
if replace: if replace:
data["replace"] = True data["replace"] = True
if should_return: if should_return:
data["return_rows"] = True data["return"] = True
response = await ds_write.client.post( response = await ds_write.client.post(
"/data/docs/-/insert", "/data/docs/-/insert",
json=data, json=data,
@ -303,7 +303,7 @@ async def test_delete_row(ds_write, scenario):
# Insert a row # Insert a row
insert_response = await ds_write.client.post( insert_response = await ds_write.client.post(
"/data/docs/-/insert", "/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={ headers={
"Authorization": "Bearer {}".format(write_token(ds_write)), "Authorization": "Bearer {}".format(write_token(ds_write)),
"Content-Type": "application/json", "Content-Type": "application/json",