New to Sequelize? Take a look at the Tutorials and Guides.
Sequelize-utility is a simple helper of Sequelize library, to efficiently interact with databases instance from Sequelize. Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. With sequelize-utility you can do operations like below in a promisified way with just simple calls:
- Establish db connection
- Establish multiple connections
- Close all connections
- Reset a table
- Sync DB
- Sync DB (For All Active Connections)
- Sync Force DB
- Sync Force DB (For All Active Connections)
- Drop all created tables from Sequelize
- Drop all created tables from Sequelize (For All Active Connections)
$ npm install --save sequelize-utility
// database.js
const { Sequelize } = require("sequelize");
module.exports.db1 = new Sequelize({
host: "host1",
username: "username1",
password: "password1",
database: "database1",
dialect: "dialect1"
});
module.exports.db2 = new Sequelize({
host: "host2",
username: "username2",
password: "password2",
database: "database2",
dialect: "dialect2"
});
// models/index.js
const { Sequelize } = require("sequelize");
const { SequelizeHelper } = require("sequelize-utility");
const dbs = require("path to database.js");
const dbHelper = new SequelizeHelper(dbs, Sequelize);
// app.js
const dbHelper = require("path to helper file");
dbHelper.closeAllConnections();
dbHelper.dropAllTablesFromAllConnections();
dbHelper.dropAllTablesFromConnection();
dbHelper.establishConnections();
dbHelper.resetTable();
dbHelper.resetTablesExcepts();
dbHelper.sync();
dbHelper.syncAll();
dbHelper.syncAllForce();
dbHelper.syncForce();