Skip to content

Commit 83ab9f7

Browse files
committed
feat: enable cross-trigger transactions via shared context
1 parent 1ae3176 commit 83ab9f7

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.gitpod.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This configuration file was automatically generated by Gitpod.
2+
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
3+
# and commit this file to your remote git repository to share the goodness with others.
4+
5+
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
6+
7+
tasks:
8+
- init: npm install && npm run build
9+
command: npm run start
10+
11+

src/Controllers/DatabaseController.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,9 +1686,14 @@ class DatabaseController {
16861686
return protectedKeys;
16871687
}
16881688

1689+
setTransactionalSession(transactionalSession) {
1690+
this._transactionalSession = transactionalSession;
1691+
}
1692+
16891693
createTransactionalSession() {
16901694
return this.adapter.createTransactionalSession().then(transactionalSession => {
16911695
this._transactionalSession = transactionalSession;
1696+
return this._transactionalSession;
16921697
});
16931698
}
16941699

src/RestWrite.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ function RestWrite(config, auth, className, query, data, originalData, clientSDK
9595
// Returns a promise for a {response, status, location} object.
9696
// status and location are optional.
9797
RestWrite.prototype.execute = function () {
98+
if (this.context.transaction) {
99+
this.config.database.setTransactionalSession(this.context.transaction)
100+
}
101+
98102
return Promise.resolve()
99103
.then(() => {
100104
return this.getUserAndRoleACL();

src/triggers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ export function getRequestObject(
281281
triggerType === Types.afterFind
282282
) {
283283
// Set a copy of the context on the request object.
284-
request.context = Object.assign({}, context);
284+
request.context = Object.assign({
285+
createTransactionalSession: config.database.createTransactionalSession.bind(config.database),
286+
commitTransactionalSession: config.database.commitTransactionalSession.bind(config.database),
287+
abortTransactionalSession: config.database.abortTransactionalSession.bind(config.database),
288+
}, context);
285289
}
286290

287291
if (!auth) {

0 commit comments

Comments
 (0)