DocsData
Batches and reasons
Several writes as one transaction, with a reason kept for each change.
A batch makes several writes as one: either all of them happen, or none do. A reason can go with them, and collections that keep history keep it with every change. To send a batch, post its requests to /api/batch:
POST /api/batch
X-Sluurp-Reason: Spring schedule
{
"requests": [
{ "method": "POST", "url": "/api/collections/shifts/records", "body": { "day": "mon", "slot": 1 } },
{ "method": "PATCH", "url": "/api/collections/shifts/records/s0000000000001", "body": { "slot": 2 } },
{ "method": "DELETE", "url": "/api/collections/shifts/records/s0000000000002" }
]
}- A batch is one transaction. If a rule or validation refuses any request, nothing is written, and the answer says which request failed.
- Each request is checked as the caller, as it would be on its own.
- A batch refuses collections that have a write hook, because a hook runs outside the transaction.
- The reason, given in the header or as
"reason"in the body, is kept with every change the batch makes.
Give a reason for one write
To give a reason for a single write, pass reason:
await sluurp.collection("prices").update(id, { value: 7 }, { reason: "Supplier price rise" });
await sluurp.collection("prices").delete(id, { reason: "Entered twice" });Reasons show in a record’s history, beside who made the change and when.