Waterline version: 0.12.2
Node version: 6.2.2
NPM version: 3.9.3
Operating system: Windows 7
Hi,
while creating the records in DB using wateline, getting below exception:
TypeError: connection.query is not a function
at CREATE (D:\Rnd\nodeRnd\waterlineRnd\node_modules\sails-mysql\lib\adapter.js:394:20)
at Object.module.exports.adapter.create (D:\Rnd\nodeRnd\waterlineRnd\node_modules\sails-mysql\lib\adapter.js:363:9)
at module.exports.create (D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\lib\waterline\adapter\dql.js:86:13)
at createValues (D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\lib\waterline\query\dql\create.js:224:16)
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\lib\waterline\query\dql\create.js:74:20
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:726:13
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:52:16
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:269:32
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:44:16
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:723:17
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:167:37
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:52:16
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:269:32
at D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\node_modules\async\lib\async.js:44:16
at .
at fn (D:\Rnd\nodeRnd\waterlineRnd\node_modules\waterline\lib\waterline\utils\callbacksRunner.js:41:10)
Below is the code snippet:
function createEmployee (callbackfunction) {
waterline.initialize(dbconfig.config, function (err, ontology) {
console.log("In create employee");
if (err) return console.error(err);
var User = ontology.collections.employee;
console.log("Making DB call");
//var employeeData = {employeeId:1, firstname:"fuser1",lastname:"luser1",email:"[email protected]",phone:"123-456-7890",age:25};
User.create({firstname:"user3"}).exec(function(err, models) {
if(err) return console.error(err);
//callbackfunction(models);
//return;
});
console.log("After create");
});
}
Below is the model:
exports.Employee = dbconfig.Waterline.Collection.extend({
identity: 'employee',
connection: 'mysqlConnection',
tableName: 'Employee',
attributes: {
employeeId: 'integer',
firstname: 'string',
lastname: 'string',
age:'integer',
emailaddress:'string',
phone:'string'
},
migrate: 'safe',
autoPK: false,
autoCreatedAt: false,
autoUpdatedAt: false
});
Kindly Suggest
Thanks,
Abhinandan
Hi @sabhinandan! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:
As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!
_If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]._
Ok, fixed!
I am seeing this same error with the same waterline version, but different node/npm/OS versions.
I'm using sails-mysql 0.11.5.
I tried to modify the api and it is working fine, although this solution is not mentioned anywhere, I just tried different combination and below combination seems to be working fine.
User.create({firstname:"user3"},function(err, models) {
if(err) return console.error(err);
//callbackfunction(models);
//return;
Thanks,
Abhinandan
@sabhinandan Thanks, this worked for me as well where exec/then did not.
@Jacob-Lynch,
I am facing issue for destroy api also, raised another issue for the same, did it work for you ?
@sabhinandan Destroy is working okay for me.
@Jacob-Lynch
Can you please post sample destroy request, I am facing issue while executing below code:
Emp.destroy({firstname:3}).exec(function(err, users) {
if (err) {return console.error(err);}
}
@sabhinandan This is working okay for me:
Model.destroy({_id: 1}).then(() => {
// result handling code
});
@Jacob-Lynch thanks a lot, I was using exec in place of then, its working now.
@Jacob-Lynch
I was facing some issue while creating relation ship also, Raised below issue for the same.
https://github.com/balderdashy/waterline/issues/1374
I would appreciate, if you can have a look into it and suggest the solution.
Thanks,
Abhinandan
+1 getting the same error over here. Issue appears to be when metaContainer (from is passed from dql.js) is passed to adapter.create (in adapter.js). The working code @sabhinandan provided has metaContainer=undefined, whereas the erroring code has metaContainer=[Switchback].
Relevant code in dql.js:
if (!hasOwnProperty(adapter, 'create')) return cb(new Error(err));
adapter.create(connName, this.collection, values, normalize.callback(function afterwards(err, createdRecord) {
if (err) {
if (typeof err === 'object') err.model = globalId;
return cb(err);
}
else return cb(null, createdRecord);
}), metaContainer);
@sabhinandan,@sailsbot,@Jacob-Lynch,@piercefreeman: Hello, I'm a repo bot-- nice to meet you!
It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message and simply close the issue if possible. On the other hand, if you are still waiting on a patch, please post a comment to keep the thread alive (with any new information you can provide).
If no further activity occurs on this thread within the next 3 days, the issue will automatically be closed.
Thanks so much for your help!
Most helpful comment
I tried to modify the api and it is working fine, although this solution is not mentioned anywhere, I just tried different combination and below combination seems to be working fine.
User.create({firstname:"user3"},function(err, models) {
if(err) return console.error(err);
//callbackfunction(models);
//return;
Thanks,
Abhinandan