azul-express
v0.1.1
Published
Transaction Middleware for Azul.js
Downloads
1
Maintainers
Readme
Azul.js Addon for Express
This addon simplifies use of Azul.js with Express. For a full overview of this module, read the Azul.js Express guide.
var azulExpress = require('azul-express')(db);
app.use(azulExpress.transaction);
app.post('/articles', azulExpress.route(function(req, res, next, Article, Author) {
Author.objects.findOrCreate({ name: req.body.author }).then(function(author) {
return author.createArticle({ title: req.body.title }).save();
})
.then(function(article) {
res.send({ article: article.json });
})
.catch(next);
}));
API
azulExpress(db)
db
Type: Database
The database from which to create transactions. The result of this call is an
object that provides the below functions. It is also an alias for the
route
function.
#route(function, [options])
function
Type: Function
An Express route (or middleware) decorated with Azul.js parameters. For detailed examples, read the full guide. This wraps the given function and returns a new function compatible with Express.
options.transaction
Type: Boolean
Enable transaction support for this route regardless of whether the
transaction
middleware is active.
options.wrap
Type: Function
Specify a wrapper function to pre-wrap the decorated route.
#transaction
Express middleware for enabling transactions.
#rollback
Express middleware for rolling back transactions. Also aliased as catch
and
error
. This is intended for advanced use and only needs to be enabled when
all of the following are true:
- The
transaction
middleware is active - The route is not wrapped by
route
- The route calls
next
with an error argument
When in doubt, enable it. It is always safe to enable.
License
This project is distributed under the MIT license.