sequelize-util
v1.0.24
Published
A utility to achieve sequelize ORM, models organization
Downloads
2
Maintainers
Readme
sequelize-util
is a simple way to organice your sequelice models, connections...
Installing
npm install --save sequelize-util
Setting up a connection
var SequelizeUtil = require("sequelize-util");
var db = SequelizeUtil({
engine: "mysql", //(oracle, mysql)
host:"localhost",
dbName:"example",
user:"root",
password:"gar",
models:"your path directory where file models are.",
//connectionString: "ora.." if engine is oracle
}, "example-dev");
Your first model
Create a folder where put your model.js filename: person.js
var Sequelize = require('sequelize');
var persons = function (sequelize) {
var model = this.define('persons',{
id : {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name : {
type: Sequelize.STRING
},
lastname : {
type: Sequelize.STRING
},
email : {
type: Sequelize.STRING
},
age : {
type: Sequelize.INTEGER
}
},{
tableName: 'person',
name: {plural:'persons', singular:'person'},
timestamps: false,
getterMethods:{
fullname: function () {
return this.name+' '+this.lastname;
}
},
});
//model.removeAttribute('id');
//model.belongsTo(this.get('project'));
}
module.exports = persons;
Your first query
var db = require('sequelize-util').getSchema("example-dev");
db.persons.findAll().then(function(users) {
console.log(users)
});
Syncing
var db = require('sequelize-util').getSchema("example-dev");
db.sync().then(function(){
console.log("Sync Done :D");
}).error(function(err){
console.log("Sync err:");
console.log(err);
})