Social Icons

twitterfacebookgoogle pluslinkedinrss feedemail


Thursday, February 28, 2013

TEIID and nodejs with node-postgres

Ok after a bit of tribulation I managed to access TEIID from nodejs.

It is really simple as the Ramesh's blog stated, but since I had a few problems making it work I try to give a bit of explanation more.

I have TEIID 8.2 on Jboss 7.1.1 and use node v0.8.16 and pg 0.13.1

The code to make connection is:

var pg = require('pg');
var connectionString = "pg://user:user@"
pg.connect(connectionString, function(err, client) {
    client.query('SELECT * FROM Reports.reports', function(err, result) {

I have nodejs on Host1 and TEIID on Host2.

The important thing that made me loose a lot of time was that I tried to connect to TEIID on port 31000 that is the default port on JDBC but … the pg protocol goes on ODBC transport

<socket-binding name="teiid-jdbc" port="31000"/>
<socket-binding name="teiid-odbc" port="35432"/>

<transport name="jdbc" socket-binding="teiid-jdbc">
<authentication security-domain="teiid-security"/>
<transport name="odbc" socket-binding="teiid-odbc" protocol="pg">
<authentication security-domain="teiid-security"/>

So the correct port to use is the ODBC one (just in case you port-offset it)

3 commenti:

Brian McRae said...
This comment has been removed by the author.
Brian McRae said...

Hi Luca!

Thank you so much for your post!

I was able to connect to the database and send a query such as client.query("SELECT * FROM Reports WHERE ReportId = 10", function(err, result) {}). Everything works well!

However, when I attempt to send a parameterized query such as client.query("SELECT * FROM Reports WHERE ReportId = $1", [10], function(err, result) {}), then the connection is terminated unexpectedly. I can confirm that it is able to find the correct rows, but the connection ends.

Have you ever experienced this? Have you used parameterized queries with node pg and TEIID?

Thank you so much, Luca!

Luca Gioppo said...

Hi Brian,
I've not experienced that problem.
Have you checked the logs on the TEIID side?
There you should find hints of the problem.
Also ... did the connection abruptly terminated or did you get some error code back?
I've not used parametric queries, which versions are you using?