-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoracle.js
More file actions
54 lines (50 loc) · 1.28 KB
/
oracle.js
File metadata and controls
54 lines (50 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const oracledb = require('oracledb');
var pool = null
try {
oracledb.initOracleClient({ libDir: "C:\\Users\\oracle-client"});
} catch (err) {
console.error('Whoops!');
console.error(err);
process.exit(1);
}
async function getPool(con) {
return new Promise(async (resolve, reject) => {
if (pool) resolve(pool)
try {
console.log("obtengo pool")
pool = await oracledb.createPool(con)
resolve(pool)
} catch (error) {
reject(error)
}
});
}
async function q(sql, parametros) {
let connection;
try {
await getPool({
user: 'c##dataos',
password: 'datos',
connectString:"37.60.236.174:1521/XE", poolAlias: "curso"
})
connection = await oracledb.getConnection("curso");
const result = await connection.execute(
sql,
parametros, { outFormat: oracledb.OBJECT },
);
return (result.rows);
} catch (err) {
return err;
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
return err;
}
}
}
}
q("SELECT * FROM CATEGORIES").then(R => {
console.log(R).catch(e => {console.log(e)})
})