How to use waterline - 10 common examples

To help you get started, we’ve selected a few waterline examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UsabilityDynamics / node-waterline-elasticsearch / examples / express.js View on Github external
app.delete( '/users', function( req, res ) {
  app.models.user.destroy( req.body, function( error ) {
    if ( error ) return res.json( { error: error });
    res.json( { status: 'ok' } );
  });
});







// Build Model
var User = waterline.Collection.extend({
  adapter: 'waterline-elasticsearch',
  tableName: 'users',
  schema: true,
  identity: 'users',
  autoCreatedAt: false,
  autoUpdatedAt: false,

  attributes: {
    type: 'string',
    body: 'array'
  }
});

new User({ adapters: { 'waterline-elasticsearch': new adapter() }}, function( error, collection ) {
  if ( error ) {
    console.log( error );
github chapmanu / hummingbird / lib / adapter.js View on Github external
module.exports.initialize = function() {
  var waterline = new Waterline();
  
  waterline.loadCollection(Waterline.Collection.extend(account_model));
  waterline.loadCollection(Waterline.Collection.extend(keyword_model));
  
  // Start Waterline
  waterline.initialize(config, function(err, models) {
    if(err) throw err;
    
    global.Account = models.collections['accounts-'+HB.env];
    global.Keyword = models.collections['keywords-'+HB.env];
    
  });
};
github devinivy / dogwater / lib / index.js View on Github external
// Give the models to waterline
    var modelDef;
    var modelExtended;
    for (var i = 0; i < models.length; i++) {

        modelDef = models[i];

        // If the provided model info is a function, it wants waterline passed to it.
        // This is used for lifecycle callbacks to have access to collections, etc.
        if (typeof modelDef === 'function') {

            modelDef = modelDef(waterline);
        }

        modelExtended = Waterline.Collection.extend(modelDef);

        waterline.loadCollection(modelExtended);
    }

    // Require the adapters modules if strings are passed instead of objects
    var keys = Object.keys(options.adapters);
    for (var j = 0; j < keys.length; j++) {

        if (typeof options.adapters[keys[j]] === 'string') {

            options.adapters[keys[j]] = require(options.adapters[keys[j]]);
        }

    }

    options.defaults = options.defaults || {};
github TendaDigital / Tournamenter / config / models.js View on Github external
module.exports = function (app, next){
  // Create new waterline ORM
  var waterline = app.waterline = new Waterline();

  // Load All controllers
  var modelsDir = path.join(__dirname, '/../models');
  var models = app.helpers.loader.load(modelsDir);

  // Convert to model object and load into waterline
  var collections = {};
  for(var k in models){
    collections[k] = Waterline.Collection.extend(models[k]);
  }

  // Config used in this waterline instance
  var config = {
    adapters: {
      'default': require(app.config.adapter)
    },

    connections: {
      default: _.defaults({adapter: 'default'}, app.config.connection),
    },

    collections,
  };

  // Initialize waterline app
github agenthunt / waterline-to-graphql / examples / waterline-example / src / main.js View on Github external
let config = {
  adapters: {
    "sails-disk": sailsDisk
  },
  connections: {
    tmp: {
      adapter: "sails-disk"
    }
  },
  defaults: {
    migrate: "drop"
  }
};

let waterlineInstance = new waterline();
models.forEach(model => {
  if (!model.connection) {
    model.connection = "tmp";
  }
  waterlineInstance.loadCollection(waterline.Collection.extend(model));
});

function setupAssociations(models) {
  _.each(models, function eachInstantiatedModel(thisModel, modelID) {
    // Bind context for models
    // (this (breaks?)allows usage with tools like `async`)
    _.bindAll(thisModel);

    // Derive information about this model's associations from its schema
    // and attach/expose the metadata as `SomeModel.associations` (an array)
    thisModel.associations = _.reduce(
github balderdashy / sails-hook-orm / lib / build-ontology-and-run-auto-migrations.js View on Github external
_.each(hook.models, function _loadEachModelDefIntoWaterline(normalizedModelDef, identity) {
      // Create a Waterline "Collection" instance for each model, then register it w/ the ORM.
      sails.log.silly('Registering model `%s` in Waterline', identity);
      orm.registerModel(Waterline.Model.extend(normalizedModelDef));
    });
github appscot / sails-orientdb / test / integration-orientdb / fixtures / bugs / 40.profileconnection.fixture.js View on Github external
/**
 * Dependencies
 */

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({

  identity: 'profileconnection',
  connection: 'associations',
  schema: false,

  attributes: {

    profileRef: {
      columnName: 'profileRef',
      type: 'string',
      foreignKey: true,
      references: 'profile40',
      on: 'id',
      onKey: 'id',
      via: 'subprofileRef'
    },
github ptariche / koa-waterline / lib / models / init.js View on Github external
settings.methods     = settings.methods    ? settings.methods    : injection.methods;

    debug('This settings getting passed in to initiate the models %s', settings);

    let orm  = new Waterline();
    let i    = Object.keys(injection.models).length - 1;
    let keys = _.keysIn(injection.models);
    let model;

    while (i > -1) {
      injection.models[keys[i]].name = keys[i];
      let _designModel       = yield designModel(injection.models[keys[i]], (injection.methods[keys[i]]) );

      debug('Thie model designed %s', _designModel);

      if (_designModel) model = Waterline.Collection.extend(_designModel);
      if (_designModel) orm.loadCollection(model);
      i--;
    }

    let results = yield ormMaker(settings, orm);
    debug('The results of the orm %s', results);

    return results;
  } catch (err) {
    debug('An error occured while trying to create the models in to the ORM');

    console.log();
    console.error(':: koa-waterline: failed to instiatiate the models ::');
    console.error(err.stack);
    console.log();
github blengerich / GenAMap / src / frontend / webapp.js View on Github external
adapter: 'psql',
            database: 'postgres',
            host: process.env.POSTGRES_PORT_5432_TCP_ADDR,
            port: process.env.POSTGRES_PORT_5432_TCP_PORT,
            user: 'postgres',
            password: config.pg
        }
    },

    defaults: {
        migrate: 'alter'
    }

}

const User = Waterline.Collection.extend({
    identity: 'user',
    tableName: 'genamapuser',
    connection: 'postgres',

    attributes: {
        id: {
            type: 'text',
            primaryKey: true,
            unique: true,
            defaultsTo: function () {
                return guid()
            }
        },
        username: {
            type: 'string',
            required: false

waterline

An ORM for Node.js and the Sails framework

MIT
Latest version published 2 years ago

Package Health Score

62 / 100
Full package analysis