8000 Couchbase support by Spyes · Pull Request #7 · RapidAPI/rapidql · GitHub
[go: up one dir, main page]

Skip to content

Couchbase support #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added update function to Couchbase
  • Loading branch information
Spyes committed Jul 22, 2017
commit 9ab5b8d78963ac46d834b4e65f66ed223d3eba57
3 changes: 2 additions & 1 deletion src/Nodes/FunctionNodes/CouchbaseDriver/CouchbaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const couchbase = require('couchbase');
const functions = {
find: require("./functions/find"),
count: require("./functions/count"),
insert: require("./functions/insert")
insert: require("./functions/insert"),
update: require("./functions/update")
};

global._couchbase_clients = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const queryString = require("../utils/queryStringGenerator");
const N1qlQuery = require('couchbase').N1qlQuery;
const uuidv1 = require("uuid/v1");

module.exports = (bucket, db, { docid = uuidv1(), data }) => {
module.exports = (bucket, db, { docid = uuidv1(), data = {} }) => {
return new Promise((resolve, reject) => {
const statement = `INSERT INTO ${bucket} ( KEY, VALUE ) VALUES ( "${docid}", ${JSON.stringify(data)} ) RETURNING META(default).id, default.*`;
const query = N1qlQuery.fromString(statement);
Expand Down
20 changes: 20 additions & 0 deletions src/Nodes/FunctionNodes/CouchbaseDriver/functions/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const queryString = require("../utils/queryStringGenerator");
const N1qlQuery = require('couchbase').N1qlQuery;
const uuidv1 = require("uuid/v1");

module.exports = (bucket, db, { KEY, WHERE, SET }) => {
return new Promise((resolve, reject) => {
const whereStr = WHERE ? `WHERE ${queryString(WHERE)}` : "";
const keyStr = KEY ? `USE KEYS "${KEY}"` : "";
const setStr = `SET ${queryString(SET)}`;
const statement =
[keyStr, setStr, whereStr, `RETURNING ${bucket}.*`].reduce((acc, str) => {
return acc += ` ${str || ""}`;
}, `UPDATE ${bucket}`);
const query = N1qlQuery.fromString(statement);
db.query(query, (error, result) => {
if (error) return reject(error);
return resolve(result[0]);
});
});
};
0