Last active
August 10, 2020 15:24
-
-
Save recursivecodes/e4370ea1552027c983ed48015c9dcb85 to your computer and use it in GitHub Desktop.
index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const oracledb = require('oracledb'); | |
oracledb.outFormat = oracledb.OBJECT; | |
oracledb.fetchAsString = [oracledb.CLOB]; | |
oracledb.autoCommit = true; | |
(async () => { | |
console.log(‘Create pool...'); | |
await oracledb.createPool({ | |
user: process.env.DB_USER, | |
password: process.env.DB_PASSWORD, | |
connectString: process.env.CONNECT_STRING, | |
}); | |
console.log('Get connection...'); | |
const connection = await oracledb.getConnection(); | |
console.log('Get SODA DB...'); | |
const soda = connection.getSodaDatabase(); | |
console.log('Get collection...'); | |
const collection = await soda.createCollection('testcollection'); | |
console.log('Insert doc...'); | |
const entry = await collection.insertOneAndGet({name: 'ava', is_cool: true, age: 14}); | |
console.log({id: entry.key, created_on: entry.createdOn}); | |
console.log('Get new doc...'); | |
const doc = await collection.find().key(entry.key).getOne(); | |
console.log(doc.getContent()); | |
console.log('Close connection...'); | |
connection.close(); | |
console.log('Close pool...'); | |
try { | |
await oracledb.getPool().close(10); | |
console.log('Pool closed'); | |
} catch(err) { | |
console.error(err); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment