Create new sequelize
Here is an example of how to create a new Sequelize instance:
const Sequelize = require('sequelize');
// Create a new Sequelize instance
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'mysql' // or 'postgres', 'sqlite', etc.
});
In this example, we're creating a new Sequelize instance with the following options:
database
: the name of the database to connect tousername
: the username to use for the connectionpassword
: the password to use for the connectionhost
: the hostname or IP address of the database server (default islocalhost
)dialect
: the type of database to connect to (e.g.mysql
,postgres
,sqlite
, etc.)
You can also specify additional options, such as:
port
: the port number to use for the connection (default is 3306 for MySQL)logging
: whether to log SQL queries and errors (default isfalse
)timezone
: the timezone to use for date and time conversions (default isUTC
)
For example:
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'mysql',
port: 3307,
logging: true,
timezone: 'America/New_York'
});
Once you've created the Sequelize instance, you can use it to create models, query the database, and perform other database operations.