Esempio n. 1
0
'use strict';

const Waterline = require('waterline');

module.exports = Waterline.Collection.extend({
  identity: 'streamer',
  connection: 'myLocalPostgres',
  attributes: {
    username: '******',
    email: 'string',
    password: '******',
    summoner_name: 'string',
    twitch_name: 'string',
    twitch_chat_password: '******'
  }
});
var Container = Waterline.Collection.extend({
  identity: 'container',
  connection: 'dockerDaemon',
  attributes: {
    name: {
      type: 'string',
      required: false,
      minLength: 5,
      maxLength: 100
    },
    hostname: {
      type: 'string',
      required: true,
      minLength: 5,
      maxLength: 100
    },
    path: {
      type: 'string',
      required: true,
      minLength: 0
    },
    config: {
      type: 'json'
    },
    priority: {
      type: 'integer'
    }
  },
  schema: false,
  afterCreate: function afterCreate() {
    debug( 'container', 'afterCreate' );
  }
});
Esempio n. 3
0
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

//create the waterline instance
var Waterline = require('waterline');
var Todo = Waterline.Collection.extend({
  tableName: 'todo',
  schema: true,
  adapter: require('sails-postgresql'),

  attributes: {
    task: {
      type: 'string',
      required: true
    },
    done: {
      type: 'boolean',
      required: true
    }
  }
});

//var postgres = require('sails-postgresql');
new Todo({}, function(err, todos) {
  todos.find()
  .exec(function(err, users) {
    console.log(users);
  });
});
Esempio n. 4
0
    defaults:{
        migrate:'alter'
    }
}

var Husband = Waterline.Collection.extend({
    identity:'husband',//模型的名称
    connection:'mysql',
    attributes: {//指定模型里面有哪些属性
        firstName: {
            type: 'string',
            required: true
        },

        lastName: {
            type: 'string',
            required: true
        },
        age: {
            type: 'string',
            required: true
        },
        wife:{
            model:'wife'
        }
    }
});


var Wife = Waterline.Collection.extend({
    identity:'wife',//模型的名称
    connection:'mysql',
Esempio n. 5
0
app.get('/operator', ensureAuthenticated, andRestrictTo('operator'), function(req, res) {
	res.end('operator');
});
app.get('/logout', function(req, res){
	req.logout();
	res.redirect('/');
});

app.get('*', function(req, res){
  res.render('404');
});
// ORM példány
var orm = new Waterline();
//orm.loadCollection(Waterline.Collection.extend(errorCollection));
orm.loadCollection(Waterline.Collection.extend(userCollection));
orm.loadCollection(Waterline.Collection.extend(footballmatchCollection));
orm.loadCollection(Waterline.Collection.extend(playereventCollection));

// ORM indítása
orm.initialize(waterlineConfig, function(err, models) {
	if(err) throw err;
	
	app.models = models.collections;
	app.connections = models.connections;
	
	// Start Server
	var port = process.env.PORT || 3000;
	app.listen(port, function () {
		console.log('Server is started.');
	});
Esempio n. 6
0
var waterline = require('waterline');

module.exports = waterline.Collection.extend({
    identity : 'reply',
    connection : 'mongo',
    schema : true,
    attributes : {
        topicID:   'string' ,
        content: 'string' ,
        replyUser:'******',
        ups:'integer'
    }
});
Esempio n. 7
0
module.exports = Waterline.Collection.extend({

	identity: 'employeeseducation',
	connection: 'myLocalMySql',

	attributes: {

		id: {
			type: 'integer',
			primaryKey: true,
			autoIncrement: true
		},

		yearOfBegin: {
			type: 'string',
			required: true
		},

		spec: {
			type: 'string',
			required: false
		},

		yearOfEnd: {
			type: 'string',
			required: true
		},

		documentNum: {
			type: 'string',
			required: false
		},

		employees: {
			model: 'employees',
			required: true
		},

		university: {
			model: 'university',
			required: false
		}
	}
});
Esempio n. 8
0
 _.each(modelDefs, function loadModelsIntoWaterline(modelDef, modelID) {
   sails.log.silly('Registering model `' + modelID + '` in Waterline (ORM)');
   waterline.loadCollection(Waterline.Collection.extend(modelDef));
 });
/**
 * Dependencies
 */

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({

  tableName: 'paymentTable',
  identity: 'payment',
  connection: 'associations',

  attributes: {
    amount: 'integer',
    type: 'string',
    apartment: {
      model: 'apartment'
    },
    customer: {
      model: 'Customer'
    },

    toJSON: function() {
      var obj = this.toObject();
      delete obj.type;
      return obj;
    }
  }

});
Esempio n. 10
0
let Loan = Waterline.Collection.extend({
  identity: 'loans',
  connection: 'myLocalPostgres',

  attributes: {
    id: {
      type: 'integer',
      autoIncrement: true,
      primaryKey: true,
      unique: true
    },
    amount: 'integer',
    balance: 'integer',
    rate_plan_id: 'integer',
    description: 'text',
    active: 'boolean',
    funded: 'boolean',

    donations: {
      collection: 'donations',
      via: 'loan'
    },
    payments: {
      collection: 'payments',
      via: 'loan'
    },
    borrower: {
      model: 'borrowers'
    },
    group: {
      model: 'groups'
    }
  }
});
Esempio n. 11
0
var Waterline = require('waterline');


module.exports = Waterline.Collection.extend({

	identity: 'position',
	connection: 'myLocalMySql',

	attributes: {

		id: {
			type: 'integer',
			primaryKey: true,
			autoIncrement: true
		},

		title: {
			type: 'string',
			required: true
		}
	}
});
/**
 * Dependencies
 */

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({

  tableName: 'taxiTable',
  identity: 'taxi',
  connection: 'associations',

  // migrate: 'drop',
  attributes: {
    medallion: 'integer',
    model: 'string',
    drivers: {
      collection: 'driver',
      via: 'taxis'
    },

    toJSON: function() {
      var obj = this.toObject();
      delete obj.medallion;
      return obj;
    }
  }
});
 _.each(fixtures, function(val, key) {
   var modelFixture = _.merge({}, defaults, fixtures[key]);
   waterline.registerModel(Waterline.Collection.extend(modelFixture));
 });
const Coach = Waterline.Collection.extend({
  identity: 'coach',
  datastore: 'default',
  primaryKey: '_id',
  attributes: {
    _id: {
      type: 'string'
    },
    name: {
      type: 'string'
    },
    train: {
      model: 'train'
    },
    class_type: {
      type: 'string'
    },
    have_wifi: {
      type: 'boolean'
    },
    have_air_conditioning: {
      type: 'boolean'
    },
    price: {
      type: 'number'
    },
    top_price: {
      type: 'number'
    },
    bottom_price: {
      type: 'number'
    },
    side_price: {
      type: 'number'
    },
    linens_price: {
      type: 'number'
    },
    wifi_price: {
      type: 'number'
    },
    is_linens_included: {
      type: 'boolean'
    },
    available_seats: {
      type: 'number'
    }
  }
});
Esempio n. 15
0
var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({
  identity: 'user',
  connection: 'mysql',

  attributes: {
    first_name: 'string',
    last_name: 'string'
  }
});
/**
 * Dependencies
 */

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({

  identity: 'customerbelongs',
  connection: 'associations',

  attributes: {
    name: 'string',
    title: 'string',
    payments: {
      collection: 'Paymentbelongs',
      via: 'customer'
    },

    toJSON: function() {
      var obj = this.toObject();
      delete obj.name;
      return obj;
    }
  }

});
Esempio n. 17
0
// RethinkDBAdapter#connectionRun executes any arbitrary ReQL query.
// connectionRun(query, cb) uses a connection from the adapter's connection pool.
rethinkDBAdapter.connectionRun(r.tableList(), function (err, result) {
	console.log('result'); // [ 'test' ]
});

var UserModel = Waterline.Collection.extend({
	adapter: 'rethinkdb',
	tableName: 'user',

	autoPK: false,

	attributes: {
		email: {
			type: 'email',
			required: true
		},
		username: {
			type: 'string',
			required: true
		},
		firstName: 'string',
		lastName: 'string'
	}
});

var User;

new UserModel({
	adapters: {
		rethinkdb: rethinkDBAdapter
Esempio n. 18
0
  defaults: {
    migrate: 'alter'
  }

};


//////////////////////////////////////////////////////////////////
// WATERLINE MODELS
//////////////////////////////////////////////////////////////////

var User = Waterline.Collection.extend({

  identity: 'user',
  connection: 'myLocalDisk',

  attributes: {
    first_name: 'string',
    last_name: 'string'
  }
});

var Pet = Waterline.Collection.extend({

  identity: 'pet',
  connection: 'myLocalMySql',

  attributes: {
    name: 'string',
    breed: 'string'
  }
});
Esempio n. 19
0
const Agents = Waterline.Collection.extend({
  identity: 'agents',
  schema: true,
  connection: 'arangodb',

  attributes: {

    id: {
      type: 'string',
      primaryKey: true,
      columnName: '_key'
    },
//    env: { type: 'string' },
    environment: {
      model: 'environments'
    },
    facts: { type: 'object' },
    ip: { type: 'string' },
    certInfo: { type: 'object' },
    lastSeen: { type: 'date' },
    platform: { type: 'string' },
    os_release: { type: 'string' },
    os_arch: { type: 'string' },
    os_family: { type: 'string' },
    os_dist_version_id: { type: 'string' },
    os_dist_name: { type: 'string' },
    os_hostname: { type: 'string' }

  }

});
Esempio n. 20
0
var Waterline = require('waterline');

var Registrants = Waterline.Collection.extend({
    identity: 'registrants',
    connection: 'mongo',
    autoCreatedAt: false,
    autoUpdatedAt: false,

    attributes: {
        name: {
            type: 'string',
            required: true,
            unique: true
        },
        password: {
            type: 'string',
            required: true
        }
    }
});

module.exports = Registrants;
Esempio n. 21
0
File: dbtest.js Progetto: freyr69/od
            schema: true,
            host: 'localhost',
            user: '******',
            password: '******', 
            database: 'od',
            timezone: '+0000'
        }
    }
};

arousalDef.identity = 'arousal';
arousalDef.connection = 'localMysql';
console.log(arousalDef);


var Arousal = Waterline.Collection.extend(arousalDef);


orm.loadCollection(Arousal);
orm.initialize(config, function(err, models) {
    if (err) {
        console.log(err);
    }
    
    models.collections.arousal.find().exec(function(err, model) {
        console.log(model);
    });
    
});

Esempio n. 22
0
  mongoAdapter=require('sails-mongo'),
  config={
    adapters:{default:mongoAdapter,mongo:mongoAdapter},
    connections:{
      localhostMongo:{
        adapter: 'mongo',host: 'localhost',port: 27017,database: 'test'
      }
    }
  };
orm.loadCollection(Waterline.Collection.extend({
  identity: 'foo',
  connection: 'localhostMongo',
  attributes: {
    name:{type:'string',required:true},
    secret:{type:'string'},
    toJSON: function() {
      var foo= this.toObject();
      delete foo.secret;
      return foo;
    }
  }
}));
orm.loadCollection(Waterline.Collection.extend({
  identity: 'bar',
  connection: 'localhostMongo',
  attributes: {
    name:{type:'string',required:true},
    foo:{model:'foo'}
  }
}));
function setupFoo(Foo){
Esempio n. 23
0
	_(collections).each(function (collection) {
		// Extend and load the Waterline collections.
		waterline.loadCollection(Waterline.Collection.extend(collection));
	});
Esempio n. 24
0
var CachedUser = Waterline.Collection.extend({

    identity: 'cachedUser',
    tableName: 'users',
    connection: 'localRedis',

    attributes: {
        id: {
            type: 'integer',
            primaryKey: true,
            unique: true
        },

        role: {
            type: 'string',
            defaultsTo: 'user',
            notNull: true
        },

        username: {
            type: 'string',
            notNull: true
        },
        
        avatar: {
            type: 'string',
            notNull: true
        },

        // List of cached message for this cached user. Shouldn't
        // be a need to actually use this. It's just here to enable
        // the database associations.
        messages: {
            collection: 'cachedMessage',
            via: 'user'
        },

        toJSON: function () {
            var obj = this.toObject();
            delete obj.createdAt;
            delete obj.updatedAt;
            return obj;
        }
    }
});
Esempio n. 25
0
var User = Waterline.Collection.extend({
    identity:'User',
    connection:'mymongo',
    schema:true,
    attributes:{
        username:{
            type:'string',
            required:true
        },
        password:{
            type:'string',
            required:true
        },
        email:{
            type:'string'
        },
        birthday:{
            type:'date',
            after:new Date('1991-01-01'),
            before:function(){
                return new Date();
            }
        },
        createTime:{
            type:'date'
        },
        migrate:'safe'
    },
    //生命周期回调
    beforeCreate:function(value,cb){
        value.createTime = new Date();
        console.log('beforeCreate executed');
        return cb();
    }
});
Esempio n. 26
0
var Waterline = require('waterline');
var CCC = Waterline.Collection.extend({
  adapter: 'mongo',
  connection: 'mongo',
  schema: false,
  identity: 'ccc',
  attributes: {
    aggregatedCount: {
      type: 'string'
    },
    rawCount: {
      type: 'string'
    },
    tags: {
      type: 'array'
    }
  }
});

module.exports = CCC;
Esempio n. 27
0
export const Schema = schema => {
    server.setConfig(conf.getConfig().server);
    server.run();

    let config = {
        adapters: {
            postgresql: postgresAdapter
        },
        connections: {
            connection: conf.getConfig().database
        }
    };

    const tableNames = Object.keys(schema);
    tableNames.forEach(tableName => {
        const table = schema[tableName];
        const atrributesNames = Object.keys(table);
        let attributes = {};

        atrributesNames.forEach(name => {
            const attribute = table[name],
                props = ['type'];

            if (typeof attribute !== 'object' || !(attribute instanceof Type)) return false;

            attributes[name] = {};
            props.forEach(
                prop => attributes[name][prop] = attribute.getProp(prop)
            );
        });



        schemes.set(tableName, { attributes, table });
    });


    for(let [name, schem] of schemes) {
        const model = Waterline.Collection.extend({
            identity: name,
            connection: 'connection',
            attributes: schem.attributes
        });

        orm.loadCollection(model);
        schemes.set(name, schem);
    }



    orm.initialize(config, function(err, models) {
        for (let [name, schem] of schemes) {
            schem.model = models.collections[name];
            schemes.set(name, schem);
        }

        if(err) throw err;
    });



};
Esempio n. 28
0
	collections.map(function(collection){
		collection.connection = config.adapter();
		// collection.connection = config.adapter();
		var collectionInstance = waterlineInstance.Collection.extend(collection)
		Waterline.loadCollection(collectionInstance)
	})
module.exports = Waterline.Collection.extend({

  tableName: 'userTable2',
  identity: 'user',
  connection: 'queryable',

  attributes: {
    first_name: 'string',
    last_name: 'string',
    email: 'string',
    title: 'string',
    phone: 'string',
    type: 'string',
    favoriteFruit: {
      defaultsTo: 'blueberry',
      type: 'string'
    },
    age: 'integer', // integer field that's not auto-incrementable
    dob: 'datetime',
    status: {
      type: 'boolean',
      defaultsTo: false
    },
    percent: 'float',
    list: 'array',
    obj: 'json',
    fullName: function() {
      return this.first_name + ' ' + this.last_name;
    }
  }

});
Esempio n. 30
0
 */
var Waterline = require('waterline');

var Request = Waterline.Collection.extend({

	identity:"request",
	schema:true,
	attributes: {

		targets: {
			collection:"target",
			via:"request"
		},
		queries:{
			collection:"query",
			via:"_request"
		},
		_relation:{
			"type":"string",
			"required":false
		},
		_formula:{
			"type": "string",
			"required": true
		}

	}

});

module.exports = Request;