kopia lustrzana https://github.com/simonw/datasette
Documentation and test for UNIQUE constraint failed, refs #1924
rodzic
9a1536b52a
commit
7fde34cfcb
|
@ -549,6 +549,17 @@ To return the newly inserted rows, add the ``"return": true`` key to the request
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
If any of your rows have a primary key that is already in use, you will get an error and none of the rows will be inserted:
|
||||||
|
|
||||||
|
.. code-block:: json
|
||||||
|
|
||||||
|
{
|
||||||
|
"ok": false,
|
||||||
|
"errors": [
|
||||||
|
"UNIQUE constraint failed: new_table.id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
.. _RowUpdateView:
|
.. _RowUpdateView:
|
||||||
|
|
||||||
Updating a row
|
Updating a row
|
||||||
|
|
|
@ -168,7 +168,7 @@ async def test_write_rows(ds_write, return_rows):
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"/data/docs/-/insert",
|
"/data/docs/-/insert",
|
||||||
{"rows": [{"id": 1, "title": "Test"}]},
|
{"rows": [{"id": 1, "title": "Test"}, {"id": 2, "title": "Test"}]},
|
||||||
"duplicate_id",
|
"duplicate_id",
|
||||||
400,
|
400,
|
||||||
["UNIQUE constraint failed: docs.id"],
|
["UNIQUE constraint failed: docs.id"],
|
||||||
|
@ -229,6 +229,9 @@ async def test_write_row_errors(
|
||||||
if special_case == "invalid_json":
|
if special_case == "invalid_json":
|
||||||
del kwargs["json"]
|
del kwargs["json"]
|
||||||
kwargs["content"] = "{bad json"
|
kwargs["content"] = "{bad json"
|
||||||
|
before_count = (
|
||||||
|
await ds_write.get_database("data").execute("select count(*) from docs")
|
||||||
|
).rows[0][0] == 0
|
||||||
response = await ds_write.client.post(
|
response = await ds_write.client.post(
|
||||||
path,
|
path,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
@ -236,6 +239,11 @@ async def test_write_row_errors(
|
||||||
assert response.status_code == expected_status
|
assert response.status_code == expected_status
|
||||||
assert response.json()["ok"] is False
|
assert response.json()["ok"] is False
|
||||||
assert response.json()["errors"] == expected_errors
|
assert response.json()["errors"] == expected_errors
|
||||||
|
# Check that no rows were inserted
|
||||||
|
after_count = (
|
||||||
|
await ds_write.get_database("data").execute("select count(*) from docs")
|
||||||
|
).rows[0][0] == 0
|
||||||
|
assert before_count == after_count
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|
Ładowanie…
Reference in New Issue