forked from oracle/json-in-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
631ba41
commit 16d6c86
Showing
41 changed files
with
5,226 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */ | ||
|
||
module.exports = { | ||
dbname : process.env.WINE_DB || "oracle" | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
|
||
|
||
var oracledb = require('oracledb'); | ||
|
||
var config = { | ||
user: process.env.NODE_ORACLEDB_USER || "scott", | ||
password: process.env.NODE_ORACLEDB_PASSWORD || "tiger", | ||
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "172.17.0.2/orclpdb", | ||
poolMin: 10, | ||
poolMax: 10, | ||
poolIncrement: 0 | ||
} | ||
|
||
async function initialize() { | ||
oracledb.autoCommit = true; | ||
await oracledb.createPool(config); | ||
var conn = await oracledb.getConnection(); | ||
var soda = conn.getSodaDatabase(); | ||
var collection = await soda.createCollection('myWines'); | ||
} | ||
|
||
async function close() { | ||
await oracledb.getPool().close(); | ||
} | ||
|
||
async function get(qbe) { | ||
var conn = await oracledb.getConnection(); | ||
var collection = await getCollection(conn); | ||
var builder = collection.find(); | ||
if (qbe != null) { | ||
builder.filter(JSON.parse(qbe)); | ||
} | ||
var docs = await builder.getDocuments(); | ||
var res = toJSON(docs); | ||
conn.close(); | ||
return res; | ||
} | ||
|
||
async function update(id, review) { | ||
delete review.id; | ||
var conn = await oracledb.getConnection(); | ||
var collection = await getCollection(conn); | ||
var result = await collection.find().key(id).replaceOne(review); | ||
conn.close(); | ||
return result; | ||
} | ||
|
||
async function create(review) { | ||
var conn = await oracledb.getConnection(); | ||
var collection = await getCollection(conn); | ||
var result = await collection.insertOneAndGet(review); | ||
var key = result.key; | ||
conn.close(); | ||
return key; | ||
} | ||
|
||
async function remove(id) { | ||
var conn = await oracledb.getConnection(); | ||
var collection = await getCollection(conn); | ||
var res = await collection.find().key(id).remove(); | ||
conn.close(); | ||
} | ||
|
||
function code() { | ||
str = ` var wine = request.body; | ||
var id = wine.id; | ||
var soda = conn.getSodaDatabase(); | ||
var collection = await soda.openCollection("myWines"); | ||
await collection.find().key(id).replaceOne(wine); | ||
`; | ||
return JSON.stringify({"value":str}); | ||
} | ||
|
||
async function getCollection(conn) { | ||
var soda = conn.getSodaDatabase(); | ||
return await soda.openCollection('myWines'); | ||
} | ||
|
||
function toJSON(documents) { | ||
var result = []; | ||
for (let i = 0; i < documents.length; i++) { | ||
var doc = documents[i]; // the document (with key, metadata, etc) | ||
var key = doc.key; | ||
content = doc.getContent(); | ||
content.id = key; // inject key into content | ||
result.push(content); | ||
} | ||
return result; | ||
} | ||
|
||
module.exports.initialize = initialize; | ||
module.exports.close = close; | ||
module.exports.get = get; | ||
module.exports.update = update; | ||
module.exports.create = create; | ||
module.exports.remove = remove; | ||
module.exports.code = code; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"paths":{"source":{"common":"src","web":"src-web","hybrid":"src-hybrid","javascript":"js","typescript":"ts","styles":"css","themes":"themes","tests":"tests"},"staging":{"web":"web","hybrid":"hybrid","themes":"themes"}},"defaultBrowser":"chrome","generatorVersion":"7.2.0"} |
Oops, something went wrong.