README
@wize/sequelize-source
Description
Loads Sequelize models using model config.json files
Usage
Installation
npm install --save @wize/sequelize-source
Initialize
import sequelizeSource from '@wize/sequelize-source';
.
.
.
/*
DB_URL: Underlying database connection string; example: <Dialect>://<username>:<password>@<DB_Host>:<DB_Port>/<Database_Name>
opts: JSON object supported by Sequelize; example: {dialect: 'postgres', logging: false, pool: {max: 1, min: 0, idle: 10000}}
*/
export default new sequelizeSource(DB_URL, opts);
Features
Authenticate
Validates if the connection to underlying DB is successful
const Source = require('./sources/postgresql').default;
.
.
Source.authenticate().then(function (){
});
readModelsFromDirectory
Defines sequelize models by reading the current config.json containing defintion of the model
Source.readModelsFromDirectory(__dirname); // __dirname should contain all the model directories containing index.js and config.json
Sample model directory, refer to test cases for implementation of models directory
project
└───models
│ └───audit
│ │ index.js
│ │ config.json
│ │ index.js
└───sources
│ └───postgres
│ │ index.js
│ app.js
│ README.md
Test
npm run test
License
MIT License