How to use the couchbase.N1qlQuery function in couchbase

To help you get started, we’ve selected a few couchbase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github couchbaselabs / devguide-examples / nodejs / query-prepared.js View on Github external
// Require Couchbase Module
var couchbase = require('couchbase');

// Setup Cluster Connection Object
var cluster = new couchbase.Cluster('couchbase://127.0.0.1');

// Setup Bucket object to be reused within the code
var bucket = cluster.openBucket('travel-sample');

// Setup Query
var N1qlQuery = couchbase.N1qlQuery;

// Make a N1QL specific Query, telling Couchbase this will be a prepared statement
var query = N1qlQuery.fromString("SELECT airportname, city, country FROM `travel-sample` " +
    "WHERE type=$1 AND city=$2").adhoc(false);

// Timing Variables to compare execution times
var t1,t2,t3,t4;

// QUERY 1 - PREPARE AND EXECUTE
// Issue Query with parameters passed in array, running as a prepared statement
bucket.query(query,["airport","London"],function(err,result,meta){
    if (err) throw err;

    // Print Results
    console.log("Result:",result);
    console.log("Time Query1:",meta.metrics.elapsedTime);
github couchbaselabs / touchbase / Touchbase / models / picturemodel.js View on Github external
var uuid 				= require("uuid");
var forge 				= require("node-forge");
var userBucket			= require("../app").userBucket;
var pictureBucket		= require("../app").pictureBucket;
var userBucketName		= require("../config").couchbase.userBucket;
var pictureBucketName	= require("../config").couchbase.pictureBucket;
var N1qlQuery 			= require('couchbase').N1qlQuery;
var multer 				= require('multer');
var fs 					= require('fs');
var gm 					= require('gm');				// you MUST 'brew install graphicsmagick' to use this library

function Picture() { };

/*Picture.upload = function(newID, params, callback) {
	if (params.picture) {
		var b64string = params.picture;
		if (b64string.search("data:image/jpg;base64") == -1 && b64string.search("data:image/jpeg;base64") == -1 && b64string.search("data:image/png;base64") == -1 && b64string.search("data:image/gif;base64") == -1) {
			callback(null, {status: 400, message: "ERROR: please use a valid image format (jpg, jpeg, png, gif)"});
			// is this callback appropriate??
		}
    	pictureBucket.insert((newID + "_pic"), params.picture, function (err, result) {
			if (err) {
			    callback(error, null);
github couchbaselabs / touchbase / TouchbaseModular / models / picturemodel.js View on Github external
var uuid                = require("uuid");
var forge               = require("node-forge");
var userBucket          = require("../app").userBucket;
var pictureBucket       = require("../app").pictureBucket;
var userBucketName      = require("../config").couchbase.userBucket;
var pictureBucketName   = require("../config").couchbase.pictureBucket;
var N1qlQuery           = require('couchbase').N1qlQuery;
var multer              = require('multer');
var fs                  = require('fs');
var gm                  = require('gm');                // you MUST 'brew install graphicsmagick' to use this library

function Picture() { };

/*Picture.upload = function(newID, params, callback) {
    if (params.picture) {
        var b64string = params.picture;
        if (b64string.search("data:image/jpg;base64") == -1 && b64string.search("data:image/jpeg;base64") == -1 && b64string.search("data:image/png;base64") == -1 && b64string.search("data:image/gif;base64") == -1) {
            callback(null, {status: 400, message: "ERROR: please use a valid image format (jpg, jpeg, png, gif)"});
            // is this callback appropriate??
        }
        pictureBucket.insert((newID + "_pic"), params.picture, function (err, result) {
            if (err) {
                callback(error, null);
github couchbaselabs / touchbase / Couch411Structure / models / sessionmodel.js View on Github external
var uuid 				= require("uuid");
var forge 				= require("node-forge");
var userBucket			= require("../app").userBucket;
var userBucketName		= require("../config").couchbase.userBucket;
var N1qlQuery 			= require('couchbase').N1qlQuery;

function Session() {};

Session.create = function(userID, callback) {
	var sessionModel = {
		type: "session",
		userID: userID,
		sessionID: (uuid.v4()+"_session"),
		expiry: 3600
	};
	userBucket.insert(sessionModel.sessionID, sessionModel, {expiry: sessionModel.expiry}, function(error, result) {
		if (error) {
    		callback(error, null);
    		return;
    	}
    	console.log(sessionModel);
github couchbaselabs / touchbase / Touchbase / models / sessionmodel.js View on Github external
var uuid 				= require("uuid");
var forge 				= require("node-forge");
var userBucket			= require("../app").userBucket;
var userBucketName		= require("../config").couchbase.userBucket;
var N1qlQuery 			= require('couchbase').N1qlQuery;
var nodemailer			= require("nodemailer");
var sgTransport 		= require('nodemailer-sendgrid-transport');
var Email 				= require("./emailmodel");

function Session() {};

Session.pathToLogin = function (req) {
	console.log(req.originalUrl);
	console.log(req.headers.host);
	var urlPath = req.originalUrl;
	var exitString = "";
	function generateExit (str) {
		var path = "";
		for (i=0; i
github couchbaselabs / touchbase / Touchbase / models / usermodel.js View on Github external
var uuid 			= require("uuid");
var forge 			= require("node-forge");
var userBucket		= require("../app").userBucket;
var userBucketName	= require("../config").couchbase.userBucket;
var N1qlQuery 		= require('couchbase').N1qlQuery;

var stringAttributes 	= ["skype", "name", "jobTitle"];
var arrayAttributes		= ["hobbies", "expertise"];
var dropdownAttributes	= ["baseOffice", "division"];

function User() { };

User.createPrimaryIndexes = function(callback) {
	var indexOnUsers = ("CREATE PRIMARY INDEX ON " + userBucketName);
    userBucket.query(indexOnUsers, function (err, result) {
		if (err) {
    		callback(error, null);
    		return;
    	}
    	callback(null, {message: "success", data: result});
	});
github RapidAPI / rapidql / src / Nodes / FunctionNodes / CouchbaseDriver / functions / count.js View on Github external
const queryString = require("../utils/queryStringGenerator");
const N1qlQuery = require("couchbase").N1qlQuery;

module.exports = (bucket, db, { WHERE, KEY }) => {
  return new Promise((resolve, reject) => {
    const whereStr = WHERE ? `WHERE ${queryString(WHERE)}` : "";
    const keyStr = KEY ? `USE KEYS "${KEY}"` : "";
    const statement = [whereStr, keyStr].reduce((acc, str) => {
      return acc += ` ${str || ""}`;
    }, `SELECT COUNT(*) AS COUNT FROM ${bucket}`);
    const query = N1qlQuery.fromString(statement);
    db.query(query, (error, result) => {
      if (error) return reject(error);
      return resolve(result);
    });
  });
};
github dsfields / couchbase-promises / lib / couchbase.js View on Github external
  static get N1qlQuery() { return couchbase.N1qlQuery; }
  static get CbasQuery() { return couchbase.CbasQuery; }
github hemerajs / hemera / packages / hemera-couchbase-store / index.js View on Github external
function hemeraCouchbaseStore(hemera, opts, done) {
  const topic = 'couchbase-store'

  const Joi = hemera.joi
  const cluster = new Couchbase.Cluster(opts.couchbase.url)
  const N1qlQuery = Couchbase.N1qlQuery

  hemera.decorate('couchbase', {
    getBucket,
    cluster
  })

  function getBucket(name) {
    if (opts.couchbase.bucketInstance) {
      return opts.couchbase.bucketInstance
    } else {
      return cluster.openBucket(name)
    }
  }

  hemera.add(
    {
github RapidAPI / rapidql / src / Nodes / FunctionNodes / CouchbaseDriver / functions / insert.js View on Github external
const queryString = require("../utils/queryStringGenerator");
const N1qlQuery = require('couchbase').N1qlQuery;
const uuidv1 = require("uuid/v1");

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);
        db.query(query, (error, result) => {
            if (error) return reject(error);
            return resolve(result[0]);
        });
    });
};