Closed ghost closed 5 years ago
I am following the example but this just does not work with Express ... :(
Nailed it ... Here is the working code ... You can update the sample in your repo based on this.
/----- sample model code -----/ var Waterline = require('waterline'); var adapter = require('sails-mysql');
// set adapter config adapter.config = { host: '127.0.0.1', port: 3306, database: 'test', user: 'root', password: '', pool: false };
// build A Model var User = Waterline.Collection.extend({ adapter: 'mysql', tableName: 'users', autoPK: false, autoCreatedAt: false, autoUpdatedAt: false, attributes: { id: { type: 'integer' }, first_name: { type: 'string' }, last_name: { type: 'string' }, date_of_birth: { type: 'date' } } });
// Load Models passing adapters in new User({ adapters: { mysql: adapter } }, function(initializeError, user) { if(initializeError){ throw initializeError }; user.findOneById(2).done(function(error, userObject){ console.log(userObject); }); })
/----- sample model code ends-/
I am trying to use waterline with express and have copy pasted the code from the example in this repo. I keep getting an error about some def.config.pool
Here is the code:
/* ------------sample model code------------- / / Waterline ORM module / var waterline = require('waterline'); / Waterline compatible MYSQL adapter */ var adapter = require('sails-mysql');
// set adapter config adapter.host = 'localhost'; adapter.database = 'test'; adapter.user = 'root'; adapter.password = ''; adapter.pool = false;
var User = waterline.Collection.extend({ adapter: 'mysql', pool: false, tableName: 'users', attributes: { id: { type: 'integer' }, first_name: { type: 'string' }, last_name: { type: 'string' }, date_of_birth: { type: 'date' } } });
// load model passing adapter in var user = new User({ adapters: { mysql: adapter }}, function(err, collection) { console.log(err); console.log(collection); });
/* ------------sample model code------------- */
Here are the error details:
D:\Projects\Realtime-Chat\node_modules\sails-mysql\lib\adapter.js:84 if (def.config.pool) { ^ TypeError: Cannot read property 'pool' of undefined at Object.module.exports.adapter.registerCollection (D:\Projects\Realtime-Chat\node_modules\sails-mysql\lib\adapter.js:84:21) at register (D:\Projects\Realtime-Chat\node_modules\waterline\lib\waterline\adapter\setupTeardown.js:25:21) at D:\Projects\Realtime-Chat\node_modules\waterline\node_modules\async\lib\async.js:108:13 at Array.forEach (native) at _each (D:\Projects\Realtime-Chat\node_modules\waterline\node_modules\async\lib\async.js:32:24) at Object.async.each (D:\Projects\Realtime-Chat\node_modules\waterline\node_modules\async\lib\async.js:107:9) at module.exports.registerCollection (D:\Projects\Realtime-Chat\node_modules\waterline\lib\waterline\adapter\setupTeardown.js:31:11) at module.exports (D:\Projects\Realtime-Chat\node_modules\waterline\lib\waterline\collection\index.js:50:17) at new child (D:\Projects\Realtime-Chat\node_modules\waterline\lib\waterline\utils\extend.js:17:39) at Object. (D:\Projects\Realtime-Chat\app.js:65:12)
11 Jan 20:33:06 - [nodemon] app crashed - waiting for file changes before starting...