Skip to main content

Access Teiid from node.js

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
    
    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 at

https://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.

Comments

  1. Which version of TEIID support this feature?
    With TEIID 8.2 there are problems.
    Any hint?
    Thanks
    Luca

    ReplyDelete
    Replies
    1. 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?

      Delete
  2. well I'm seeing nothing it seems that the node application does not issue any request.
    Are you testing it just local or also on different machines?
    I have TEIID on host1 and node on host2 and nothing ...

    ReplyDelete
  3. Luca,

    I only tested locally, if there is any trick you had to make it work, please do explain here for others.

    Thanks

    Ramesh..

    ReplyDelete
  4. Hello all,

    Has anyone tried using a parameterized query with node pg and JBoss? Sending a text query works fine just as you explained (client.query('SELECT CustomerID, ContactName, ContactTitle FROM Customers').

    However, if we try:
    client.query('SELECT CustomerID, ContactName, ContactTitle FROM Customers WHERE CustomerID = $1', [100])

    Then, the JBoss connection is closed. We can confirm that rows of data are returned, however, the node pg module seems to detect that stream has ended, and thus it throws the error "Error: Connection terminated unexpectedly".

    Has anyone else experienced this?

    ReplyDelete
  5. Hi Unknown,

    Could you turn this question into a JIRA issue? Can you provide information such as the Teiid version and the pg package version?

    ReplyDelete
    Replies
    1. Hi Steven!

      Thank you so much for the fast response! We will go ahead and turn the question into a JIRA issue!

      In the meantime, would you happen to have an example of using a parameterized query with the node pg module and Teiid? Are you aware if other people have successfully done this?

      Thank you so much, Steven!

      Brian

      Delete
    2. Brian,

      Thanks for logging https://issues.jboss.org/browse/TEIID-5014 it will be addressed in subsequent releases.

      Delete
  6. Hi man! Good article! I have one question, its possible connect to Teiid with PHP.. im use PHP a lot.... indeed, i use Codeigniter, you thinks that the connection its posible?
    Thanks! :D

    ReplyDelete
  7. PHP should be possible using their pg connectivity. We have not explicitly tested that path though. If you run into issues, please use the forums or JIRA - https://issues.jboss.org/projects/TEIID

    ReplyDelete

Post a Comment

Popular posts from this blog

Teiid Spring Boot 1.7.0 Released

Teiid Spring Boot version 1.7.0 to support Teiid 16.0 has been released. This release is mainly to support the Teiid's latest version.  In this release, the support for OpenAPI code generation based on VDB has been removed as there is no community interest and moreover it was at OpenAPI 2.0, and the industry has moved to 3.0 and beyond. There are no plans to further pursue this feature. VDB maven plugin was also removed, which was intended to be a replacement for the VDB importing feature was to be used when working on OpenShift, however, since it requires the Maven repository and does not completely represent the feature as defined on the WildFly based deployments this is also removed. You can still use the VDB import feature with Teiid Spring Boot, simply define the VDB with your "IMPORT DATABASE" statements and provide the additional files along with the main VDB file. During the start of the application, Teiid Spring Boot will load all the necessary DDL files for the ...

Expose Excel Data as OData feed using Teiid

For that matter you can expose any data source that is supported by Teiid through its translators as OData service. You can convert Relational databases XML, JSON, CSV files Web Services  Sales Force Excel documents sources, or write your on top of your specific source. Teiid added support for exposing its virtual database (VDB) as OData service without any additional work. Create a virtual database with your required sources and create any additional views and deploy in the the JBoss EAP 6.1 server, that has Teiid 8.3 or greater installed.  See https://docs.jboss.org/author/display/teiid84final/OData+Support  for more information. So, lets build a simple example of exposing the Excel Sheet. Teiid accesses Excel sheets via JDBC-ODBC bridge, and Windows OS provides a ODBC driver for Excel documents.  Edit the standalone-teiid.xml, and create Connection Factory jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};Dbq=c:\ODBC\ExcelDat...

Teiid 8.13.3 Released

Teiid 8.13.3 is now  available .  In total 8.13.3 addresses 10 issues since 8.13.2: [ TEIID-4028 ] - adding salesforce-34 resource adapter does not work through the cli [ TEIID-4066 ] - Odata translator ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl [ TEIID-4070 ] - Issues with resource adapters with api modules in wildfly [ TEIID-4089 ] - Teiid JDBC driver does not reset the update count when calling getMoreResults(int) [ TEIID-4093 ] - OData authentication fails with NPE when gss-pattern related properties are included in VDB [ TEIID-4096 ] - AssertionError with independent side of a dependent join that has an ordered limit [ TEIID-3050 ] - allow for more incremental insert with iterator [ TEIID-4075 ] - Netezza translator to support common table expressions [ TEIID-4098 ] - Always preserve columns order in google spreadsheets models [ TEIID-4046 ] - OData - $skip is bee...