Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect KnexJS with database Oracle?

I have connection but i do not know if it exists in connection the key odbc... but even if i throw it away the error informed below persists

const knex = require('knex');

// connection database
const dbmdlog = knex({
  client: 'oracle',
  connection: {
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: 'mydb',
    odbc: 'MYDB'
  }
});

module.exports = dbmdlogp;

I'm doing a select simple in a collun
But always return error:

  Unhandled rejection TypeError: _this2.driver.connect is not a function
        at /var/www/html/myapp/node_modules/knex/lib/dialects/oracle/index.js:143:21
        at Promise._execute (/var/www/html/myapp/node_modules/bluebird/js/release/debuggability.js:299:9)
        at Promise._resolveFromExecutor (/var/www/html/myapp/node_modules/bluebird/js/release/promise.js:481:18)
        at new Promise (/var/www/html/myapp/node_modules/bluebird/js/release/promise.js:77:14)
        at Client_Oracle.acquireRawConnection (/var/www/html/myapp/node_modules/knex/lib/dialects/oracle/index.js:142:12)
        at Object.create (/var/www/html/myapp/node_modules/knex/lib/client.js:231:16)
        at Pool._createResource (/var/www/html/myapp/node_modules/generic-pool/lib/generic-pool.js:326:17)
        at Pool.dispense [as _dispense] (/var/www/html/myapp/node_modules/generic-pool/lib/generic-pool.js:314:12)
        at Pool.acquire (/var/www/html/myapp/node_modules/generic-pool/lib/generic-pool.js:392:8)
        at /var/www/html/myapp/node_modules/knex/lib/client.js:281:19
        at Promise._execute (/var/www/html/myapp/node_modules/bluebird/js/release/debuggability.js:299:9)
        at Promise._resolveFromExecutor (/var/www/html/myapp/node_modules/bluebird/js/release/promise.js:481:18)
        at new Promise (/var/www/html/myapp/node_modules/bluebird/js/release/promise.js:77:14)
        at Client_Oracle.acquireConnection (/var/www/html/myapp/node_modules/knex/lib/client.js:272:12)

        at /var/www/html/myapp/node_modules/knex/lib/runner.js:200:30
     at Promise._execute (/var/www/html/myapp/node_modules/bluebird/js/release/debuggability.js:299:9)
like image 479
Noah Avatar asked Oct 15 '25 16:10

Noah


1 Answers

A combination of knex and OracleDB works fine. Here are packages from package.json: "knex": "0.13.0", "oracledb": "1.13.1"

And the knex call:

var conn = knex({
  client: 'oracledb',
  connection: {
    host: config.oracle.host,
    user: config.oracle.user,
    password: config.oracle.password,
    database: config.oracle.database,
  }
});
like image 134
Laurent Avatar answered Oct 18 '25 12:10

Laurent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!