https://github.com/seangenabe/mongodb-transaction-daemon
[DEPRECATED: MongoDB supports transactions now.] MongoDB transaction helper
https://github.com/seangenabe/mongodb-transaction-daemon
Last synced: 7 months ago
JSON representation
[DEPRECATED: MongoDB supports transactions now.] MongoDB transaction helper
- Host: GitHub
- URL: https://github.com/seangenabe/mongodb-transaction-daemon
- Owner: seangenabe
- License: mit
- Created: 2018-01-31T16:09:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-10T09:58:14.000Z (over 6 years ago)
- Last Synced: 2024-04-14T05:28:06.938Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# mongodb-transaction-daemon
MongoDB transaction helper.
## Usage
```typescript
import { TransactionDaemon } from 'mongodb-transaction-daemon'
const daemon = new TransactionDaemon()
const users = db.collection('users')
// Register a method.
daemon.register('awesomeInTwoSteps', {
lockOnCollections: {
users: {
read: true,
write: true
}
},
*plan(context, _id, first, second) {
// The generator function is merely a convenience.
// We need to be able to resume execution at any point.
// Do not put MongoDB operations in the planning phase.
yield async c => {
await users.updateOne({ _id }, { a: first })
}yield async c => {
await users.updateOne({ _id }, { a: second })
await c.setResult('ok')
}
}
})
// Invoke.
await daemon.invoke('awesomeInTwoSteps', 1, 2) // ok
```See the [API](./api.md).