Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What goes in the Sequelize "config file"?

Tags:

I'm just starting out with Sequelize in Node.js and finding the documentation really lacking. I have a 'db' module in which I connect to the database via Sequelize, and this reads in configuration from an application-wide config file at ./config.json relative to the root of my project. This is a nested configuration and extremely unlikely to be structured in the way that Sequelize wants a config file for the CLI.

Now I'm trying to use migrations and the documentation makes reference to a "config file". I know I can set the path to that config file, but what the heck do I put in it? It's not documented anywhere (that I've seen).

like image 436
d11wtq Avatar asked Aug 03 '14 06:08

d11wtq


People also ask

What is migration file in Sequelize?

A Migration in Sequelize is a javascript file which exports two functions, up and down , that dictates how to perform the migration and undo it. You define those functions manually, but you don't call them manually; they will be called automatically by the CLI.

What is the use of Sequelize-CLI?

Sequelize-cli is a very useful command-line interface for creating models, configurations and migration files to databases. It's integrated with Sequelize middleware and operates with many relational databases such as PostgreSQL, MySQL, MSSQL, Sqlite.

What is required true in Sequelize?

This is the case because, when the where option is used inside an include , Sequelize automatically sets the required option to true . This means that, instead of an OUTER JOIN , an INNER JOIN is done, returning only the parent models with at least one matching children.


1 Answers

There are more things you could put into a config file:

var sequelize = new Sequelize(config.database.dbName, config.database.master.user,     config.database.master.password, {     dialect: config.database.protocol,     port: config.database.port,     host: config.database.master.host,     /* You could setup replication as well     replication: {      read: [      {        host: config.database.master.host,        username: config.database.master.host,        password: config.database.master.password      },      {        host: config.database.master.host,        username: config.database.master.host,        password: config.database.master.password      }      ],      write: {        host: config.database.master.host,        username: config.database.master.host,        password: config.database.master.password      }      */     },     pool: {         maxConnections: config.database.pool.maxConnections,         maxIdleTime: config.database.pool.maxIdleTime     },      logging: false,     define: {         underscored: false,         freezeTableName: false,         syncOnAssociation: true,         charset: 'utf8',         collate: 'utf8_general_ci',         classMethods: {method1: function() {}},         instanceMethods: {method2: function() {}},         timestamps: true         schema: "prefix"     } }), 
like image 60
siyang Avatar answered Sep 21 '22 05:09

siyang