node-oracledb thin 模式试用
node-oracledb client 已经支持thin 模式了,npm 包小了很多,以下是一个测试
环境准备
基于容器部署的oracle
- docker-compose
version: '3'
services:
db:
image: gvenzl/oracle-xe:21.3.0-slim
ports:
- "1521:1521"
environment:
- ORACLE_PASSWORD=Ccda5662E
- APP_USER=dalong
- APP_USER_PASSWORD=Ccda5662E
node-oracledb 代码测试
- app.js
const oracledb = require('oracledb');
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
const mypw = "Ccda5662E" // set mypw to the hr schema password
async function run() {
const connection = await oracledb.getConnection ({
user : "system",
password : mypw,
connectString : "localhost/XEPDB1"
});
const result = await connection.execute(
`select 'dalong' as demo from dual`
);
console.log(result.rows);
await connection.close();
}
run();
- 效果
说明
从使用上发现还会很方便的,包括安装以及代码集成
参考资料
https://github.com/oracle/node-oracledb
https://node-oracledb.readthedocs.io/en/latest/user_guide/introduction.html#getting-started-with-node-oracledb