# new Transaction(configopt) → {object}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
object
|
<optional> |
|
id |
object
|
<optional> |
Optional transaction id |
operations |
object
|
<optional> |
List of operations to perform in the transaction (can be added later with addOperation method) |
userId |
object
|
<optional> |
User who triggered the transaction, in case we need to timestamp the updated records |
this
object
Example
// A transaction looks like this.
// Each operation contains the target model, target record, and updates to perform on the record
{
"id": "98650fb1-9288-4be9-a611-394211e9fff9",
"operations": [{
"action": "update",
"modelId": "d620b995-89a1-4f1b-a4c6-a4a11949de94",
"recordId": "6ab2f4fd-e6f3-4fc3-998f-96629e7ef109",
"updates": {
"SJg2oX@w": "New project name"
}
}, {
"action": "update",
"modelId": "01f6c940-e247-4d85-9f35-e3d59ea49289",
"recordId": "5eb85fe3-2634-466c-839f-08423fc1cac1",
"updates": {
"yUbNrXw9": "New project name"
}
}, {
"action": "update",
"modelId": "01f6c940-e247-4d85-9f35-e3d59ea49289",
"recordId": "5ae68056-f099-473b-8f5f-af9eeec9ddff",
"updates": {
"yUbNrXw9": "New project name"
}
}, {
"action": "update",
"modelId": "01f6c940-e247-4d85-9f35-e3d59ea49289",
"recordId": "1f7f9d6a-2cbc-42f1-80c4-8ad795141493",
"updates": {
"yUbNrXw9": "New project name"
}
}]
}
Methods
# addOperation(operation) → {object}
Add an operation to the Transaction. A single operation can contain multiple field updates.
Parameters:
Name | Type | Description |
---|---|---|
operation |
object
|
|
action |
string
|
Only "update" at the moment. Will support "insert" and "delete" in the future. |
modelId |
string
|
The target model (allow to batch the operations by database table) |
recordId |
string
|
The record to update |
updates |
object
|
The update to apply to the record |
The transaction itself (makes the method chainable)
object
Example
myTransaction.add({
action: "update",
modelId: "project",
recordId: "5eb85fe3-2634-466c-839f-08423fc1cac1",
updates: {
name: "New project name",
status: "pending"
}
})