操作系统:windows10 64位
数据库版本:DM8 1-1-156-20.12.07-131023-ENT
Node.js 的版本至少为 v12.0.0。
C:\Users\Administrator>node -v
v12.18.3
C:\Users\Administrator>npm install dmdb
安装部署如有问题参考 https://www.npmjs.com/package/node-gyp,其它问题均可百度解决
C:\Users\Administrator>npm install -g node-gyp
C:\WINDOWS\system32>npm install --global windows-build-tools
C:\WINDOWS\system32>cd D:\nodejs\
D:\nodejs>npm install dmdb
npm WARN saveError ENOENT: no such file or directory, open 'D:\nodejs\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'D:\nodejs\package.json'
npm WARN nodejs No description
npm WARN nodejs No repository field.
npm WARN nodejs No README data
npm WARN nodejs No license field.
+ dmdb@1.0.5537
updated 2 packages in 19.427s
3 packages are looking for funding
run `npm fund` for details
D:\nodejs>npm init -y
npm WARN nodejs@1.0.0 No description
npm WARN nodejs@1.0.0 No repository field.
+ dmdb@1.0.5537
removed 435 packages and updated 1 package in 10.163s
// 引入 dmdb 包
var db = require('dmdb');
var fs = require('fs');
var pool, conn;
var http = require('http');
async function example() {
try {
pool = await createPool();
conn = await getConnection();
await queryWithResultSet();
} catch (err) {
console.log(err);
} finally {
try {
await conn.close();
await pool.close();
} catch (err) {}
}
}
example();
/* 创建连接池 */
async function createPool() {
try {
return db.createPool({
connectString: "dm://SYSDBA:SYSDBA@localhost:5236?autoCommit=false",
poolMax: 10,
poolMin: 1
});
} catch (err) {
throw new Error("createPool error: " + err.message);
}
}
/* 获取数据库连接 */
async function getConnection() {
try {
return pool.getConnection();
} catch (err) {
throw new Error("getConnection error: " + err.message);
}
}
/* 查询产品信息表 */
async function queryWithResultSet() {
try {
var sql = "SELECT ID,NAME FROM SYSDBA.T2";
var result = await conn.execute(sql, [], { resultSet: true });
var resultSet = result.resultSet;
// 从结果集中获取一行
result = await resultSet.getRow();
while (result) {
console.log(result);
result = await resultSet.getRow();
}
} catch (err) {
throw new Error("queryWithResultSet error: " + err.message);
}
}
D:\nodejs>node C:\Users\Administrator\Desktop\test1.js
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'dmdb'
D:\nodejs\node_modules
D:\>node C:\Users\Administrator\Desktop\test1.js
[ 1, 'a' ]
[ 2, 'b' ]
[ 3, 'c' ]
操作系统:Centos7 64 位
数据库版本:DM8 1-1-156-20.12.07-131023-ENT
Node.js 的版本至少为 v12.0.0。
[root@192 ~]# tar zxvf node-v14.16.0-linux-x64.tar.xz
[root@192 ~]# mv node-v14.16.0-linux-x64/ /home/dmdba
[root@192 ~]# chown -R dmdba.dinstall /home/dmdba/node-v14.16.0-linux-x64/
[root@192 ~]# su - dmdba
[dmdba@192 bin]$ ./node -v
v14.16.0
[dmdba@192 ~]$ vi .bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/dmdba/node-v14.16.0-linux-x64/bin
export PATH
[dmdba@192 ~]$ source .bash_profile
[dmdba@192 ~]$ npm install dmdb
> snappy@6.3.5 install /home/dmdba/node_modules/snappy
> prebuild-install || node-gyp rebuild
。。。。中间略。。。。。。
+ dmdb@1.0.5537
added 68 packages from 47 contributors and audited 68 packages in 45.453s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
[dmdba@192 ~]$ cd node_modules/
[dmdba@192 node_modules]$ pwd
/home/dmdba/node_modules
[dmdba@192 node_modules]$ ls dmdb/
index.d.ts index.js LICENSE package.json README.md src
## 测试脚本按上面章节内容
[dmdba@192 ~]$ node test1.js
[ 1, 'a' ]
[ 2, 'b' ]
[ 3, 'c' ]
[dmdba@192 ~]$ node test1.js
[ 'DM Database Server x64 V7.6.0.184-Build(2019.08.08-110764)ENT \n' ]
[ 'DB Version: 0x7000a' ]
[dmdba@192 ~]$
文章
阅读量
获赞