Microsoft SQL Server adapter for waterline. Built for Microsoft SQL Server 2012 and newer.
$ npm install waterline-mssql --save
var adapter = require('waterline-mssql');
var Waterline = require('waterline');
var waterline = new Waterline();
var config = {
adapters: {
default: adapter
},
connections: {
default: {
adapter: 'default',
database: 'database_name',
host: 'addrestohost',
port: 1433,
user: 'dbo',
persistent: true,
password: 'superlongpassword'
}
},
defaults: {
migrate: 'create'
}
};
waterline.initialize(config, function (err, data) {
if (err) {
throw err;
}
var collections = data.collections;
var connections = data.connections;
});
var bcrypt = require('bcrypt');
var userModel = {
attributes: {
name: {
type: 'string',
required: true
},
email: {
type: 'string',
required: true,
unique: true,
size: 255 // defaults to 'max'
},
password: {
type: 'string',
required: true
},
role: {
model: 'role'
}
},
beforeCreate: function (values, next) {
bcrypt.hash(values.password, 8, function (err, hash) {
if (err) {
return next(err);
}
values.password = hash;
next();
});
}
};
waterline.initialize(config, function (err, data) {
if (err) {
throw err;
}
var collections = data.collections;
var connections = data.connections;
// start transaction
collections.usermodel.transaction.start(function(err) {
// commit transaction
collections.userModel.transaction.commit(function(err) {
});
// rollback transaction
collections.usermodel.transaction.rollback(function(err) {
});
})
});