Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Liana = require('forest-express-sequelize');
- const express = require('express');
- const initCollections = require('./collections');
- const initModels = require('./models');
- const Sequelize = require('sequelize');
- const sequelize = new Sequelize({
- dialect: 'sqlite',
- storage: 'database.sqlite',
- });
- const models = initModels(sequelize);
- const app = express();
- // We can get rid of modelsDir, because all the models informations are in sequelize and
- // mongoose instances.
- // Here the example could also work with a factory instead (`const liana = createLiana({...})`).
- const liana = new Liana({
- envSecret: process.env.FOREST_ENV_SECRET,
- authSecret: process.env.FOREST_AUTH_SECRET,
- sequelize: models.sequelize,
- });
- // To initialize a collection, just call a member function. This is a more familiar way to do
- // for nodejs users than a static function of the forest-express-sequelize module. It is
- // rarely a good idea to use a module as singleton, difficult to understand what is the inner logic,
- // like how the static functions are related to the initialization. Also,
- // a singleton forbid to have multiple instances of the liana in the same app.
- liana.collection('user', {});
- // And we can still put the collections initializations in a folder if we need. This is very
- // straightforward, no documentation is needed (and potentially less support), we just do like we
- // would do with anything in nodejs. Again familiarity is key.
- // Also, we can get rid of the `configDir` option.
- initCollections(liana);
- app.use(liana.createMiddleware());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement