Skip to content

Commit

Permalink
Add wine demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 18, 2019
1 parent 631ba41 commit 16d6c86
Show file tree
Hide file tree
Showing 41 changed files with 5,226 additions and 0 deletions.
5 changes: 5 additions & 0 deletions WineDemo/db/dbconfig.js
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"
};
97 changes: 97 additions & 0 deletions WineDemo/db/wines-oracle.js
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;
1 change: 1 addition & 0 deletions WineDemo/oraclejetconfig.json
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"}
Loading

0 comments on commit 16d6c86

Please sign in to comment.