0.0.7 • Published 4 years ago
@mashbot/sequelize-factory v0.0.7
sequelize-factory
SequelizeFactory provides helpers to the Sequelize ORM framework to primarily load the models, run migrations and apply specific treatments to those models.
This is typically performed on every project that utilizes Sequelize, but not in a standardized way. By incorporating these features here, it will reduce the effort on each project and allow developers to focus on the models and the application logic.
Outside of loading the models and applying the migrations, the Factory will also apply plugins against each model. These plugins may be community driven or private features. Examples of these may be;
- create GraphQL types, queries and mutations
- create gRPC protobufs and services
- register with an Elasticsearch instance
- add helper methods such as: findByPk()
// from your index.js
const Models = require('./models')
// ./models/index.js
import {initializeFactory} from '@mashbot/sequelize-factory'
import ElasticsearchPlugin from '@mashbot/sequelize-elasticsearch'
import GraphqlPlugin from '@mashbot/sequelize-graphql'
const models = initializeFactory({
config: {}, // sequelize connection details
extension: '', // if different than .model.js
modelsPath: '', // if different than current folder
migrationsPath: '', // if different than /migrations
plugins: [{
type: ElasticsearchPlugin,
config: {}
}, {
type: GraphqlPlugin,
config: {}
}]
})
module.exports models
// Using models across your project
const Models = require('/models')
const Rider = Models.Rider