oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.24k stars 1.07k forks source link

use thick mode oracledb in M1 #1632

Closed babpulss closed 6 months ago

babpulss commented 6 months ago

I'm trying to use oracle 11g, too old to supported for thin mode, with thick mode here's error I've been through.

oracledb library reads the value of the BINARY_FILE variable based on process.arch, so an error occurs that the binary file cannot be found when running on an arm-based notebook such as M1. (node_modules/oracledb/lib/util.js:48)

Eventually, the file becomes oracledb-6.2.0-darwin-arm64, which cannot be found. Therefore, you can specify BINARY_FILE as oracledb-6.2.0-darwin-x64.node.

Additionally, since Nodejs 18 version is running on arm-based, you must install it after forcibly switching to x86 from zsh.

arch -x86_64 zsh

After the installation is complete, you can switch back to zsh to run it.

arch -arm64 zsh
cjbj commented 6 months ago

Thanks for sharing.

Can you recheck? node-oracledb 6 Thin mode doesn't require anything special on Apple Silicon for me - it just works:

const oracledb = require('oracledb');
const dbConfig = require('./dbconfig.js');

async function doit() {
  console.log("Run at: " + new Date());
  console.log("Node.js version: " + process.version + " (" + process.platform, process.arch + ")");
  console.log("Node-oracledb version:", oracledb.versionString);
  if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
    console.log("Oracle Client library version:", oracledb.oracleClientVersionString);
  }

  let connection = await oracledb.getConnection(dbConfig);
  console.log("Oracle Database version:", connection.oracleServerVersionString);

  const sql = `SELECT UNIQUE CLIENT_OCI_LIBRARY, CLIENT_VERSION, CLIENT_DRIVER
         FROM V$SESSION_CONNECT_INFO
         WHERE SID = sys_context('USERENV', 'SID')`;

  const result = await connection.execute(sql);
  console.dir(result.rows[0], { depth: null });

  connection.close();

}

doit();

gives

Run at: Thu Dec 14 2023 13:04:01 GMT+1000 (GMT+10:00)
Node.js version: v18.18.2 (darwin arm64)
Node-oracledb version: 6.2.0
Oracle Database version: 23.4.0.23.11
[ 'Unknown', '6.2.0.0.0', 'node-oracledb : 6.2.0 thn' ]

This shows my Node.js binary is arm64.

For Thick mode and older releases, yes you need do use an Intel stack, see https://medium.com/oracledevs/how-to-install-node-oracledb-5-5-and-oracle-database-on-apple-m1-m2-silicon-941fccda692f

babpulss commented 6 months ago

Ah, I didn't mention using thick mode

sharadraju commented 6 months ago

@babpulss please let us know if you have tried @cjbj's suggestion?

babpulss commented 6 months ago

@babpulss please let us know if you have tried @cjbj's suggestion?

I manually changed file name oracledb-6.2.0-darwin-x64.node to oracledb-6.2.0-darwin-arm64 in node_modules