Remove by id¶
Deletes one row. The answer is the row as it was, so the caller can show or log what is gone.
In short
DELETE /api/schema/<user-path>/<instance>/<database>/<table>/<id>- An unknown id deletes nothing and answers
data: null, unless you ask for a404. - To delete many rows, use remove by query.
| Method | DELETE |
| URL | /api/schema/admin/mysql8/inventory/customers/:id[/:primaryKey] |
| Body | none |
| Query params | select, deep, throwErrorIfRecordNotFound |
| Answer | data : the removed row, or null |
| Databases | MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server, Oracle, TiDB, Percona |
| Cached | no. It clears the cached answers of the table. |
| From code | g.sys.db.removeById |
| API id | SCHEMA_DEL_DELETE_BY_ID |
| Without a schema | /api/gen/admin/mysql8/inventory/customers/:id[/:primaryKey] : below |
The examples change the table of get all.
The call¶
{
"success": true,
"statusCode": 200,
"data": { "customer_id": 1, "first_name": "Bob", "last_name": "Lin", "last_update": "2022-11-14T04:34:58.000Z", "pincode": 382345, "isActive": 1 }
}
By another column : DELETE /api/schema/admin/mysql8/inventory/customers/Bob/first_name removes the first row whose first_name is Bob.
Options¶
| Option | What it does |
|---|---|
?throwErrorIfRecordNotFound=true |
An unknown id answers 404 : Record not found. |
?select=first_name |
Keeps some columns of the removed row in the answer. |
?deep=… |
Adds the related rows of the removed row to the answer. |
Only the rows of the caller¶
Remove by id reads no find from the URL. A pre hook can add one to g.req.query.find. The row is then removed only when it matches both the id and that find.
After the call¶
The cached answers of the table are cleared, and WebSocket subscribers get the news. Post hooks get the removed row in g.res.output.
From your code¶
g.sys.db.removeById makes the same call from custom APIs, hooks, events, schedulers and test cases.
Without a schema : /api/gen¶
Every table also answers this operation under /api/gen, with or without a schema :
| URL | /api/gen/admin/mysql8/inventory/customers/:id[/:primaryKey] |
| API id | GEN_DEL_DELETE_BY_ID |
| From code | g.sys.db.gen.removeByIdGen |
Without a schema, the id takes the type it looks like. On MongoDB, an id that looks like an ObjectId is one.
Headers and errors¶
This operation takes the request headers of every API. It answers the envelope, with the status codes and the messages of every API.
Related : All APIs · Table schema · Pre hooks · Post hooks · API group permission