
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
sequelize-database-connector
Advanced tools
This will help to connect and register model for database like MySQL and PostgreSQL
sequelize-connector is an npm package that simplifies the process of connecting to a Sequelize database like 'mysql' | 'postgres' | 'mariadb' | 'mssql' | 'db2' | 'oracle' | 'snowflake'. It provides an easy-to-use interface for setting up and managing database connections.
To install the package, use npm:
npm install sequelize-connector
First, import the sequelize-connector package and configure your database connection:
db/index.ts
import path from 'path';
import { SequelizeConnector } from 'sequelize-connector';
import { SequelizeConnectorOptions } from 'sequelize-connector/dist/types';
const sqConf: SequelizeConnectorOptions = {
dbConfig: {
dbDialect: 'mysql',
dbHost: 'localhost',
dbName: 'todo',
dbUser: 'root',
dbPassword: 'root',
dbLogging: false,
},
modelsPath: path.join(__dirname, '../models'),
};
const connector = new SequelizeConnector(sqConf);
const dbInstance = connector.getSequelizeInstance();
const getModels = connector.getModels.bind(connector);
const getModel = connector.getModel.bind(connector);
const closeDBConnection = connector.closeDBConnection.bind(connector);
export { dbInstance, getModels, getModel, closeDBConnection };
Define your models using Sequelize:
import { Sequelize, DataTypes } from 'sequelize';
export default (sequelize: Sequelize, dataTypes: typeof DataTypes) => {
const User = sequelize.define(
'Users',
{
id: {
type: dataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: dataTypes.STRING,
allowNull: false,
},
email: {
type: dataTypes.STRING,
allowNull: false,
unique: true,
},
},
{
tableName: 'users',
timestamps: false,
},
);
return User;
};
Sync your models with the database:
sequelize.sync({ force: true }).then(() => {
console.log('Database & tables created!');
});
Here's a sample code to create and retrieve data:
// Create a new user
import { getModel } from '../db/index';
await getModel('User')
.create({
name: 'Kartick Dey',
email: 'kartick@kd.com',
})
.then((user) => {
console.log('User created:', user.toJSON());
});
// Retrieve all users
await getModel('User')
.findAll()
.then((users) => {
console.log('All users:', JSON.stringify(users, null, 2));
});
|-------------------|---|
| getSequelizeInstance | |
|-------------------|---|
| Description | This function returns an instance of Sequelize, which is used to interact with the database. |
| Parameters | None |
| Returns | {Sequelize} An instance of Sequelize. |
|-------------------|---|
|-------------------|---|
| getModels | |
|-------------------|---|
| Description | Retrieves all the models defined in the Sequelize instance. |
| Parameters | None |
| Returns | {Object} An object containing all the Sequelize models. |
|-------------------|---|
|-------------------|---|
| closeDBConnection | |
|-------------------|---|
| Description | Closes the current database connection. |
| Parameters | None |
| Returns | Promise<void> - Resolves when the connection is successfully closed. |
|-------------------|---|
Contributions are welcome! Please open an issue or submit a pull request for any changes.
For any questions or issues, please contact kartick.dey1995@gmail.com.
FAQs
This will help to connect and register model for database like MySQL and PostgreSQL
We found that sequelize-database-connector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.