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);
}));
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.
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.
Type: Boolean
Enable transaction support for this route regardless of whether the
transaction
middleware is active.
Type: Function
Specify a wrapper function to pre-wrap the decorated route.
Express middleware for enabling transactions.
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.
This project is distributed under the MIT license.