Are you writing a "node.js" application and would like to access Teiid VDB from it?
If "yes", this is currently possible using NPM package "pg". Since, Teiid supports the PG transport, you can use this PostgreSQL client for "node.js" for accessing the Teiid.
For example if you have VDB called "northwind" deployed on your Teiid server, and it has table called "customers" and you are using default configuration such as
user = 'user'
password = 'user'
host = 127.0.0.1
port = 35432
then you can use following to write simple access program to Teiid
If "yes", this is currently possible using NPM package "pg". Since, Teiid supports the PG transport, you can use this PostgreSQL client for "node.js" for accessing the Teiid.
For example if you have VDB called "northwind" deployed on your Teiid server, and it has table called "customers" and you are using default configuration such as
user = 'user'
password = 'user'
host = 127.0.0.1
port = 35432
then you can use following to write simple access program to Teiid
var pg = require('pg');
var connectionString = "pg://user:user@localhost:35432/northwind"
pg.connect(connectionString, function(err, client) {
client.query('SELECT CustomerID, ContactName, ContactTitle FROM Customers', function(err, result) {
console.log(result.rows)
});
});
If you want access one row at a time, you can also use event mechanism and write var pg = require('pg');
var connectionString = "pg://user:user@localhost:35432/northwind"
pg.connect(connectionString, function(err, client) {
var query = client.query('SELECT CustomerID, ContactName, ContactTitle FROM Customers');
query.on('row', function(row) {
console.log(row);
});
query.on('error', function(error) {
console.log("failed to query");
});
query.on('end', function(error) {
console.log("closing client");
client.end();
});
});
For more information please take look athttps://npmjs.org/package/pg
https://github.com/brianc/node-postgres
If you do write an application using these please do share your experiences with us.
Which version of TEIID support this feature?
ReplyDeleteWith TEIID 8.2 there are problems.
Any hint?
Thanks
Luca
I tested with 8.3, but it should work with 8.2 as I did not find any fixes that related to postgres port in 8.3 cycle. what errors are you seeing?
Deletewell I'm seeing nothing it seems that the node application does not issue any request.
ReplyDeleteAre you testing it just local or also on different machines?
I have TEIID on host1 and node on host2 and nothing ...
OK now it works!!!!
ReplyDeleteLuca,
ReplyDeleteI only tested locally, if there is any trick you had to make it work, please do explain here for others.
Thanks
Ramesh..