Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A simple example of how to use Waterline v0.10 with Express
- */
- var _ = require('lodash');
- var Waterline = require('waterline');
- // Instantiate a new instance of the ORM
- var orm = new Waterline();
- //////////////////////////////////////////////////////////////////
- // WATERLINE CONFIG
- //////////////////////////////////////////////////////////////////
- // Require any waterline compatible adapters here
- var diskAdapter = require('sails-disk');
- var mysqlAdapter = require('sails-mysql');
- // Build A Config Object
- var config = {
- // Setup Adapters
- // Creates named adapters that have have been required
- adapters: {
- 'default': diskAdapter,
- disk: diskAdapter,
- mysql: mysqlAdapter
- },
- // Build Connections Config
- // Setup connections using the named adapter configs
- connections: {
- myLocalDisk: {
- adapter: 'disk'
- },
- myLocalMySql: {
- adapter: 'mysql',
- host: 'localhost',
- database: 'foobar',
- user: 'root',
- password: ''
- }
- },
- defaults: {
- migrate: 'alter'
- }
- };
- //////////////////////////////////////////////////////////////////
- // WATERLINE MODELS
- //////////////////////////////////////////////////////////////////
- var User = Waterline.Collection.extend({
- identity: 'user',
- connection: 'myLocalMySql',
- attributes: {
- first_name: 'string',
- last_name: 'string'
- }
- });
- var Pet = Waterline.Collection.extend({
- identity: 'pet',
- connection: 'myLocalMySql',
- attributes: {
- name: 'string',
- breed: 'string'
- }
- });
- // Load the Models into the ORM
- orm.loadCollection(User);
- orm.loadCollection(Pet);
- //////////////////////////////////////////////////////////////////
- // START WATERLINE
- //////////////////////////////////////////////////////////////////
- // Start Waterline passing adapters in
- orm.initialize(config, function(err, models) {
- if(err) throw err;
- console.log('OK');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement