安装
npm i egg-oracle --save
// {app_root}/config/plugin.js 启用插件
module.exports = {
oracle :{
enable: true,
package: ‘egg-oracle’,
}
};
// {app_root}/config/config.default.js 增加配置
config.oracle = {
client: {
user: ‘cps2’,
password: ‘cps2’,
connectString: ‘localhost/gym’,
},
};
// {app_root}/app/service/my_service.js 例子
// {app_root}/app/service/my_service.js
‘use strict’;
const Service = require(‘egg’).Service;
class MyService extends Service {
// example for getConnection
async foo() {
const connection = await this.app.oracle.getConnection();
const result = await connection.execute(‘SELECT sysdate AS “date” FROM dual’);
connection.close();
console.log(result.rows[0].date);
}
}
module.exports = MyService;