numtel/meteor-mysql

Select from event on client

iuraya opened this issue · 1 comments

Hi,

I'm trying to do a select from the client to retrieve some info but nothing happens in the callback of the method call:

Client side:
Template.register.events({
'submit form': function(event) {
event.preventDefault();
var email = $('[name="email"]').val();
Meteor.call('test', email, function(error, result) {
if (error) {
console.log(error);
}
else {
alert ('done');
}
});
}
});

Server side:
Meteor.methods ({
'test': function(email) {
return liveDb.select(
'SELECT * FROM users WHERE email = ' + liveDb.db.escape(email),
[
{
table: 'users',
condition: function(row, newRow, rowDeleted) {
return row.email === email || (newRow && newRow.email === email);
}
}
]
);
},
});

Also I would like to ask if I can place a subscription on the router. I've tryied this:
Router.route('/register', {
name: 'register',
template: 'register',
waitOn: function () {
return new MysqlSubscription('users');
}
});

but I get in the console:
Array.MysqlSubscription (http://localhost:3000/packages/numtel_mysql.js?2e45f0a77d68e6539440f2906b8d222a016f04d5:78:34)
at Router.route.waitOn (http://localhost:3000/app/lib/routes.js?0fb139054a3010f38f3b325bea97f9ae71509ff7:24:12)
at http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:441:22
at Array.forEach (native)
at Function..each..forEach (http://localhost:3000/packages/underscore.js?fa590de5090ceb4a42555b48562fd8f8e7035758:157:11)
at RouteController._runRoute (http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:440:5)
at Function.Route.dispatch (http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:856:18)
at route (http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:713:11)
at boundNext (http://localhost:3000/packages/iron_middleware-stack.js?ff70621b6c5f6a406edc60600c4b76126dae21d6:425:31)
at Meteor.bindEnvironment (http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:22)

Thank you very much

It is no use to return a LiveMysqlSelect object from a Meteor method. Either change it to a publication for live updates or if you want to retrieve the results from a query just once, return the results using liveDb.db.query() as defined by node-mysql.