-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsimple.js
executable file
·54 lines (47 loc) · 1.6 KB
/
simple.js
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
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown
* at http://oss.oracle.com/licenses/upl
*
* DESCRIPTION
* Makes a connection, inserts one row, selects the inserted row, and drops trhe table
*/
'use strict';
var oracledb = require('oracledb');
var accessControl = require('./AccessControl');
oracledb.initOracleClient();
async function run() {
let connection;
try {
let credentials = accessControl.getCredentials("simple.js");
connection = await oracledb.getConnection({
user: credentials['-u'], password: credentials['-p'], connectString: credentials['-c']
});
let result;
await connection.execute("CREATE TABLE employees(first_name VARCHAR2(20), last_name VARCHAR2(20))");
console.log("Table has been created");
const values = [["ROBERT", "ROBERTSON"], ["ANDY", "ANDREWS"], ["MICHAEL", "MICHAELSON"]];
await connection.executeMany("INSERT INTO employees VALUES(:1, :2)", values);
console.log("Inserted", values.length, "employees into the table");
result = await connection.execute("SELECT first_name, last_name FROM employees");
result.rows.forEach(function(row){
console.log("Selected employee:", row[0], row[1]);
});
await connection.execute("DROP TABLE employees");
console.log("Table has been dropped");
}
catch (err) {
console.log(err);
}
finally {
if (connection) {
try {
connection.close();
console.log("Connection has been released");
}
catch (err) { console.log(err); }
}
}
}
run();