0.3.1 • Published 7 years ago

waterline-models v0.3.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

waterline-models

NPM version Dependency Status Dev Dependency Status Code Climate Build Status Coverage Status

Auto loads waterline models from a directory

Looking for another maintainer. I no longer use waterline and would like to have someone else take over. If you are interested, please reach out. Otherwise, eventually I will have this package removed. I doubt this module is used enough for people to read this, but in case it is read, there's your notice.

Installation

npm install --save waterline-models

Usage

models/user.js

module.exports = {
  identity: 'user',
  connection: 'default',
  attributes: {
    firstName: 'string',
    lastName: 'string'
  }
};

app.js

var path = require('path');
var waterlineModels = require('waterline-models');
waterlineModels.init({
  dir: path.join(__dirname, 'models'),
  adapters: {
    memory: require('sails-memory-adapter')
  },
  connections: {
    default: {
      adapter: 'memory'
    }
  }
});

// This could be in another file
var User = require('waterline-models')('user'); // pass in the identity

User
  .then(function (Model) {
    return Model.create({
      firstName: 'Jack',
      lastName: 'Bliss'
    });
  })
  .then(function (user) {
    console.log(user);
    // {
    //   firstName: 'Jack',
    //   lastName: 'Bliss',
    //   createdAt: Some Date,
    //   updatedAt: Some Date,
    //   id: 1
    // }
  });

Options

cwd

The cwd directory to work off of when reading from the models directory

Default: process.cwd()

dir

The path to your models directory

Default: 'models'

defaultCollection

All other options are passed into waterline's initialize method as the configuration which is documented here.

0.3.1

7 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago