Sequelize.js

Sequelize.js --node ORM

提供对MySQL,MariaDB,SQLite和PostgreSQL数据库的简单访问,通过映射数据库条目到对象,或者对象到数据库条目。

install

$ npm install --save sequelize

建立连接

var sequelize = new Sequelize(
'database',
 'username',
 'password', 
 {
   host: 'localhost',
   dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql',
   pool: { max: 5, min: 0, idle: 10000 }, // SQLite only
   storage: 'path/to/database.sqlite'
  }  
);

创建modal

var User = sequelize.define('user', 
{ 
  firstName: {
   type: Sequelize.STRING,
   field: 'first_name' 
  },
  lastName: {
   type: Sequelize.STRING 
  }
}, {
 freezeTableName: true // 
}
);

User.sync({force: true}).then(function () { // Table created
   return User.create({ firstName: 'John', lastName: 'Hancock' });
});

你可能感兴趣的:(Sequelize.js)