Created
October 17, 2014 02:07
-
-
Save nrmitchi/a4cf49631fcac4417493 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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