Skip to content

Instantly share code, notes, and snippets.

@nrmitchi
Created October 17, 2014 02:07
Show Gist options
  • Save nrmitchi/a4cf49631fcac4417493 to your computer and use it in GitHub Desktop.
Save nrmitchi/a4cf49631fcac4417493 to your computer and use it in GitHub Desktop.
module.exports = function(sequelize, DataTypes) {
var Model = sequelize.define('Model', {
dates : {
type : DataTypes.ARRAY(DataTypes.DATE) ,
allowNull : false ,
validate : {
isDate : true
}
}
}, {
paranoid: true ,
tableName: 'models' ,
associate: function(models) {},
classMethods: {},
instanceMethods: {}
});
return Model
}
var Sequelize = require('sequelize');
var db = new Sequelize('array-test-db', 'user', 'password', {
dialect: 'postgres',
protocol: 'postgres',
port: '5432',
host: 'localhost',
logging: console.log, //false // This should be false in prod
define: {
timestamps: true , // Enable timestamps for all models
underscored: true // Use underscore style foreign keys and timestamps
}
});
var model = db.import('/workspace/env/sequelize-postgres-min-ex/minimal-example-model.js')
console.log(" Loaded "+model.name)
db.sync({ force: true })
.complete(function(err) {
if (err) {
throw err
}
// Load model
var m = model.build({
dates : [new Date()]
});
m.save()
.success( function (n) {
console.log("Saved")
})
.error( function (err) {
// Todo: What to do when delivery creation fails
console.log("ERROR:"+err)
console.log(err.stack)
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment