Skip to content

Instantly share code, notes, and snippets.

@martinaglv
Created April 3, 2014 09:08
Show Gist options
  • Save martinaglv/9951072 to your computer and use it in GitHub Desktop.
Save martinaglv/9951072 to your computer and use it in GitHub Desktop.
var Bookshelf = require('bookshelf');
var MySql = Bookshelf.initialize({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root',
password : '',
database : 'testdb',
charset : 'utf8'
}
});
var User = MySql.Model.extend({
tableName: 'users',
initialize: function(){
this.on('saving', this.validate, this);
},
validate: function(){
throw new Error('this is always thrown!');
}
});
new User({ col: '12345' }).save().catch(function(e){
console.log('Error: ', e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment