I am not able to use a5.sql.connection() to access database
I am on build 2999_4519 and trying to access database using NodeJS from alpha, but it is failing at the
var cn = new a5.sql.connection() line. I have provided the site, database credentials etc.
I referred to:
http://www.alphasoftware.com/alphafo...ghlight=nodejs
and
http://www.alphasoftware.com/blog/re...a-anywhere-3-0
I am not sure what am I missing when using a5.sql.connection().
As a workaround I used pool.getConnection(function(err,connection){} to directly access a mysql database and it worked fine.
Regards!
I am on build 2999_4519 and trying to access database using NodeJS from alpha, but it is failing at the
var cn = new a5.sql.connection() line. I have provided the site, database credentials etc.
I referred to:
http://www.alphasoftware.com/alphafo...ghlight=nodejs
and
http://www.alphasoftware.com/blog/re...a-anywhere-3-0
I am not sure what am I missing when using a5.sql.connection().
As a workaround I used pool.getConnection(function(err,connection){} to directly access a mysql database and it worked fine.
exports.handler = function(packet,response,sendResponse) {
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 100,
host : '',
user : '',
password : '',
database : '',
debug : false
});
var e;
var attachments = null;
var msg = 'Hello database: ' + packet.firstname + ' ' + packet.lastname;
response.result = msg;
// here query database table
pool.getConnection(function(err,connection){
if (err) {
connection.release();
response.result = 'Error with database';
sendResponse(response,attachments);
return;
}
else
{
// no database connection error
// Start sql here
connection.query("select * from users",function(err,rows,fields){
connection.release();
if(!err) {
var attachments = null;
for (var i in rows) {
//console.log('Post Titles: ', rows[i].username);
response.result = response.result + ' ' + rows[i].username;
}
sendResponse(response,attachments);
return;
};
});
// End sql here
}
});
};
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 100,
host : '',
user : '',
password : '',
database : '',
debug : false
});
var e;
var attachments = null;
var msg = 'Hello database: ' + packet.firstname + ' ' + packet.lastname;
response.result = msg;
// here query database table
pool.getConnection(function(err,connection){
if (err) {
connection.release();
response.result = 'Error with database';
sendResponse(response,attachments);
return;
}
else
{
// no database connection error
// Start sql here
connection.query("select * from users",function(err,rows,fields){
connection.release();
if(!err) {
var attachments = null;
for (var i in rows) {
//console.log('Post Titles: ', rows[i].username);
response.result = response.result + ' ' + rows[i].username;
}
sendResponse(response,attachments);
return;
};
});
// End sql here
}
});
};