Skip to content

Unofficial Microsoft SQL Server Adapter for waterline

Notifications You must be signed in to change notification settings

gleam-ru/waterline-sqlserver

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microsoft SQL Server adapter for waterline. Built for Microsoft SQL Server 2012 and newer.

Installing

$ npm install waterline-sqlserver --save

Usage

Configuration and initialization

var adapter = require('waterline-sqlserver');
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;
});

Collection/Model definition

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();
    });
  }

};

About

Unofficial Microsoft SQL Server Adapter for waterline

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%