How to use the marklogic.queryBuilder function in marklogic

To help you get started, we’ve selected a few marklogic 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 marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / index.js View on Github external
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');

var funcs = {};
var moment = require('moment-timezone');
// funcs.exploreSearch = require('./exploreSearch');
funcs.patch = require('./patch');

funcs.search = function (spec) {
  // TODO: should really be supporting the txid param
  // query function wants an args list so we use apply since we
  // are dynamically creating values out of what is specified
  // console.log(require('util').inspect(this));
  // console.log(JSON.stringify(spec));
  return this.documents.query.apply(
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / old / patchQuestion.js View on Github external
* Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var _ = require('lodash');
var uuid = require('node-uuid');

var db;
var questionsDir = '/questions/';
var contributorPrefix = 'com.marklogic.samplestack.domain.Contributor';
var contributorDir = contributorPrefix + '/';
// TODO: pull contributor info from session
var contributorId = 'cf99542d-f024-4478-a6dc-7e723a51b040';
var contributorDisplayName = 'JoeUser';
var contributorUserName = 'joe@example.com';

var commentTemplate = {
  'owner': {
    'id': contributorId,
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / util.js View on Github external
var Promise = require('bluebird');
var errs = libRequire('errors');
var qb = require('marklogic').queryBuilder;

module.exports = {
  // POJO-managed docs "bury" the content under a Java fully qualified
  // class name, so we find the first key an use it to locate the actual
  // content
  unwrapPojo: function (pojo) {
    return pojo[Object.keys(pojo)[0]];
  },

  getOnlyContent: function (response) {
    if (response.length !== 1) {
      throw errs.cardinality({ length: response.length,
        response: response });
    }
    else {
      return response[0].content;
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / index.js View on Github external
*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');

var funcs = {};

/**
 * Handle an update to a contributor's reputation by patch the document.
 *
 * @param  {String} txid The transaction ID.
 * @param  {String} id The contributor ID.
 * @param  {Number} repChange Increment or decrement value.
 * @return {Promise} A promise object.
 */
funcs.patchReputation = function (txid, id, repChange) {
  // add (or subtract) from reputation property
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / old / getContributor.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;

module.exports = function (userSpec) {
  var self = this;

  return new Promise(function (resolve, reject) {
    // TODO: should thie really be approx. 2-times slower? are we missing
    // an index?
    // self.documents.query(
    //   qb.where(
    //     qb.directory('com.marklogic.samplestack.domain.Contributor/'),
    //     qb.value('id', userId)
    //   )
    // ).result(
    //
    var fetch;
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / old / postQuestion.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;
var _ = require('lodash');
var uuid = require('node-uuid');

var generateUUID = function () {
  return uuid.v4();
};

var questionTemplate = {
  'accepted':false,
  'acceptedAnswerId':null,
  'answerCount':0,
  'answers':[],
  'comments':[],
  'creationDate':new Date(),
  'id':'',
  'itemTally':0,
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / old / getQuestion.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;

module.exports = function (userSpec) {
  var self = this;

  return new Promise(function (resolve, reject) {
    var fetch = self.documents.read(
        '/questions/' + userSpec.questionId + '.json'
      );
    fetch.result(
      function (response) {
        if (response.length !== 1) {
          return reject({
            error: 'cardinalityViolation',
            userSpec: userSpec,
            count: response.length
          });
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / patch.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');
var errs = libRequire('errors');
var moment = require('moment-timezone');
var Promise = require('bluebird');

var qnaDoc = require('./index');

module.exports = function (txid, spec) {
  var self = this;

  /**
   * Handles an upvote or downvote for a Samplestack question or answer.
   * Performs three patch operations:
   *   1. Adds the contributor ID to the array of upvoters or
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / old / getQuestions.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;

module.exports = function (userSpec) {
  var self = this;

  return new Promise(function (resolve, reject) {

    var questionsDir = '/questions/';
    var length = 10;
    var start = (userSpec.start) ? parseInt(userSpec.start) : 1;
    var searchText = (userSpec.q) ? userSpec.q : '';
    var fetch = self.documents.query(
      qb.where(
        qb.directory(questionsDir),
        qb.parsedFrom(searchText)
      ).slice(start,length).withOptions({categories: 'none'})
    );
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / old / searchContributors.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;

module.exports = function (userSpec) {
  var self = this;

  return new Promise(function (resolve, reject) {

    var contributorsDir = 'com.marklogic.samplestack.domain.Contributor/';
    var length = 10;
    var start = (userSpec.start) ? userSpec.start : 1;
    var searchText = (userSpec.q) ? userSpec.q : '';
    var fetch = self.documents.query(
      qb.where(
        qb.directory(contributorsDir),
        qb.parsedFrom(searchText)
      ).slice(start,length).withOptions({categories: 'none'})
    );