kopia lustrzana https://github.com/simonw/datasette
Renamed return_rows to return in insert API
Refs https://github.com/simonw/datasette/issues/1866#issuecomment-1313128913pull/1912/head
rodzic
65521f03db
commit
264d0ab471
|
@ -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]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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",
|
||||
|
|
Ładowanie…
Reference in New Issue