Search code examples
javascriptnode.jsjdbcignite

Can't access metadata of ignite database using JDBC (Node.js)?


I'm trying to access my metadata in order to list the tables on my ignite database using this two approaches, but all I can get is my schema name and nothing from the getmetadata method, and for that I'm using the following code:

var JDBC = require('jdbc');
var metadata = require('jdbc-metadata');
var async = require("async");
var jinst = require('jdbc/lib/jinst');
var ResultSet = require('jdbc/lib/resultset');
var databasemetadata = require('jdbc/lib/databasemetadata');

if (!jinst.isJvmCreated()) {
  jinst.addOption("-Xrs");
  jinst.setupClasspath([appRoot2 + '/ignite-core-2.4.0.jar']);
}

var config = {
  // Ignite configuration to your server
  url: 'jdbc:ignite:thin://host:port',
  drivername: 'org.apache.ignite.IgniteJdbcThinDriver',
  minpoolsize: 1,
  maxpoolsize: 100,
  properties: {}
};

var igniteConn = new JDBC(config);
igniteConn.initialize(function(err) {
  if (err) {
    done(err);
    return console.error('Connection Error: ' + err);
    saveToLog(req, 'Error on connection: ' + err, 300, 'JO-002', '');
  } else {
    console.log("connection established");
  }
});

igniteConn.reserve(function(err, connObj) {
      if (connObj) {
        console.log("Using connection: " + connObj.uuid);
        var conn = connObj.conn;
        async.series([

          function(callback) {
            conn.getSchema(function(err, res) {
              if (err) {
                callback(err);
              } else {
                console.log(res);
                callback(res);
              }
            });
          },
          function(callback) {
            conn.getMetadata(function(err, res) {
              if (err) {
                callback(err);
              } else {
                console.log("///////");
                console.log(res);
                callback(res);
              }
            });
          }
        ], function(err, results) {
          // Check for errors if need be.
          // results is an array.
        });

The second approach using the driverManager:

var drivermanager = require('jdbc/lib/drivermanager');
drivermanager.getConnection(config.url, null, null, function(err, conn) {
  if (err) throw err;
  testconn = new Connection(conn);

  if (testconn) {
    async.series([
      function(callback) {
        testconn.getMetaData(function(err, result) {
          if (err) callback(err);
          console.log(result);
          /*
          else {
            result.getTables(null,null,null,null,function(err,res){
              if(err) callback(err);

              else {                      
                console.log(res);
              }

            });
          }*/
          //resultSet = result.getTables(null, null, null,"TABLE");
        });
      },
    ], function(err, results) {
      // Results can also be processed here.
      // Release the connection back to the pool.
    });
  }
});

I can run queries against my tables normally for the information. If anyone has any suggestions, how I can get to my metadata or if you know the query that I can run for getting that if there's any other alternatives (like SELECT information.tabels ... but this is not working on ignite) that would be really appreciated.


Solution

  • The following snippet worked for me:

    var config = {
      libpath: 'ignite-core-2.4.0.jar',
      // Ignite configuration to your server
      url: 'jdbc:ignite:thin://127.0.0.1',
      drivername: 'org.apache.ignite.IgniteJdbcThinDriver',
      minpoolsize: 1,
      maxpoolsize: 100,
      properties: {}
    };
    
    var jdbcMetadata = new metadata(config);
    
    jdbcMetadata.metadata(function (err, metadata) {
        console.log('Getting tables...');
    
        jdbcMetadata.tables({schema: "PUBLIC", types: ['TABLE', 'VIEW']}, function (err, tables) {
            console.log(tables);
    
            jdbcMetadata.close(function(err) {
              console.log('Connection closed');
            });
        });
    });
    

    I could see:

    [ { tableCat: null,
        tableSchem: 'PUBLIC',
        tableName: 'A',
        tableType: 'TABLE',
        remarks: null,
        typeCat: null,
        typeSchem: null,
        typeName: null,
        selfReferencingColName: null,
        refGeneration: null } ]