Cannot pass parameters to mysql-co query??
Closed this issue · 2 comments
SimonFearby commented
I can't find a way to pass parameters to this mysql-co. The code flow below is used and as soon as i add parameters the datasbe call is skipped??
var koa = require('koa');
var route = require('koa-route');
var json = require('koa-json');
var bodyParser = require('koa-bodyparser');
var mysql = require('mysql-co');
var connection = mysql.createConnection({ host : 'localhost', user : 'theuser', password : 'thepassword', database : 'thedatabse' });
var app = koa();
app.use(bodyParser());
app.use(route.post('/api/v1/path1/path2/', function*() {
// { boring body and payload validation removed..... }
var paramvar1 = "asdf";
var paramvar2 = "qwer";
var paramvar3 = "zxcv";
var result = yield connection.query("SELECT field1, field2 FROM thedatabase.thetable WHERE (field3 = ?) AND (field4 = ?) AND (field5 = ?) AND (active = 1) AND (lockedout = 0);", [paramvar1, paramvar2, paramvar3] );
// { code removed}
}));
var server = app.listen(3000, function() {
console.log('API func ABC server listening on port 3000');
});
sidorares commented
hi @SimonFearby the example looks ok to me. Do you have any exception thrown from yield
call?
Also, node-mysql2 now has promise wrappers built in so no need for external library like mysql-co
SimonFearby commented
Thanks for the reply.
The exception is an unrelated link to the next line (just setting a variable)
var rangetouse = 3000; // Default to 3000
TypeError: Cannot read property 'userrange' of undefined
It is as if the following line is being included as a return function.
I'll check out node-mysql2