How to use the js-data.utils.forOwn function in js-data

To help you get started, we’ve selected a few js-data 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 js-data / js-data-sql / src / index.js View on Github external
applyWhereFromObject (sqlBuilder, where, opts) {
    utils.forOwn(where, (criteria, field) => {
      if (!utils.isObject(criteria)) {
        criteria = { '==': criteria }
      }
      // Apply filter for each operator
      utils.forOwn(criteria, (value, operator) => {
        let isOr = false
        if (operator && operator[0] === '|') {
          operator = operator.substr(1)
          isOr = true
        }
        let predicateFn = this.getOperator(operator, opts)
        if (predicateFn) {
          sqlBuilder = predicateFn(sqlBuilder, field, value, isOr)
        } else {
          throw new Error(`Operator ${operator} not supported!`)
        }
github js-data / js-data-sql / src / index.js View on Github external
utils.forOwn(where, (criteria, field) => {
      if (!utils.isObject(criteria)) {
        criteria = { '==': criteria }
      }
      // Apply filter for each operator
      utils.forOwn(criteria, (value, operator) => {
        let isOr = false
        if (operator && operator[0] === '|') {
          operator = operator.substr(1)
          isOr = true
        }
        let predicateFn = this.getOperator(operator, opts)
        if (predicateFn) {
          sqlBuilder = predicateFn(sqlBuilder, field, value, isOr)
        } else {
          throw new Error(`Operator ${operator} not supported!`)
        }
      })
    })
    return sqlBuilder
github GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
filterQuery (dsQuery, query, opts) {
    query = utils.plainCopy(query || {});
    opts || (opts = {});
    opts.operators || (opts.operators = {});
    query.where || (query.where = {});
    query.orderBy || (query.orderBy = query.sort);
    query.orderBy || (query.orderBy = []);
    query.skip || (query.skip = query.offset);

    // Transform non-keyword properties to "where" clause configuration
    utils.forOwn(query, (config, keyword) => {
      if (reserved.indexOf(keyword) === -1) {
        if (utils.isObject(config)) {
          query.where[keyword] = config;
        } else {
          query.where[keyword] = {
            '==': config
          };
        }
        delete query[keyword];
      }
    });

    // Apply filter
    if (Object.keys(query.where).length !== 0) {
      utils.forOwn(query.where, (criteria, field) => {
        if (!utils.isObject(criteria)) {
github js-data / js-data-express / src / index.js View on Github external
throw new Error('You must provide an instance of JSData.Container, JSData.DataStore, or JSData.Mapper!')
  }

  const router = this.router = express.Router()
  router.use(bodyParser.json())
  router.use(bodyParser.urlencoded({
    extended: true
  }))

  if (utils.isFunction(config.request)) {
    router.use(config.request)
    config.request = undefined
  }

  if (component instanceof Container) {
    utils.forOwn(component._mappers, (mapper, name) => {
      let endpoint = `/${mapper.endpoint || name}`
      if (utils.isFunction(config.getEndpoint)) {
        endpoint = config.getEndpoint(mapper)
      }
      router.use(endpoint, new Router(mapper, config).router)
    })
  } else if (component instanceof Mapper) {
    const createManyHandler = makeHandler('createMany', component, config)
    const createHandler = makeHandler('create', component, config)
    const updateManyHandler = makeHandler('updateMany', component, config)
    const updateAllHandler = makeHandler('updateAll', component, config)

    router.route('/')
      // GET /:resource
      .get(makeHandler('findAll', component, config))
      // POST /:resource
github js-data / js-data-http / src / index.js View on Github external
return false
      } else {
        delete opts.params[parentKey]

        if (utils.isObject(id)) {
          item = id
        }

        if (item) {
          parentId = parentId || def.getForeignKey(item) || (def.getLocalField(item) ? utils.get(def.getLocalField(item), parentDef.idAttribute) : null)
        }

        if (parentId) {
          delete opts.endpoint
          const _opts = {}
          utils.forOwn(opts, (value, key) => {
            _opts[key] = value
          })
          utils._(_opts, parentDef)
          endpoint = makePath(this.getEndpoint(parentDef, parentId, _opts), parentId, endpoint)
          return false
        }
      }
    })
github GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
utils.forOwn(query.where, (criteria, field) => {
        if (!utils.isObject(criteria)) {
          query.where[field] = {
            '==': criteria
          };
        }

        utils.forOwn(criteria, (value, operator) => {
          let isOr = false;
          let _operator = operator;
          if (_operator && _operator[0] === '|') {
            _operator = _operator.substr(1);
            isOr = true;
          }
          const predicateFn = this.getOperator(_operator, opts);
          if (predicateFn) {
            if (isOr) {
              throw new Error(`Operator ${operator} not supported!`);
            } else {
              dsQuery = predicateFn(dsQuery, field, value);
            }
          } else {
            throw new Error(`Operator ${operator} not supported!`);
          }
github js-data / js-data-firebase / src / index.js View on Github external
return collectionRef.once('value').then((dataSnapshot) => {
      const data = dataSnapshot.val()
      if (!data) {
        return [[], { ref: collectionRef }]
      }
      const records = []
      utils.forOwn(data, (value, key) => {
        records.push(value)
      })
      const _query = new Query({
        index: {
          getAll () {
            return records
          }
        }
      })
      return [_query.filter(query).run(), { ref: collectionRef }]
    })
  },
github js-data / js-data-rethinkdb / src / index.js View on Github external
_applyWhereFromObject (where) {
    const fields = []
    const ops = []
    const predicates = []
    utils.forOwn(where, (clause, field) => {
      if (!utils.isObject(clause)) {
        clause = {
          '==': clause
        }
      }
      utils.forOwn(clause, (expr, op) => {
        fields.push(field)
        ops.push(op)
        predicates.push(expr)
      })
    })
    return {
      fields,
      ops,
      predicates
    }
github js-data / js-data-rethinkdb / src / index.js View on Github external
utils.forOwn(where, (clause, field) => {
      if (!utils.isObject(clause)) {
        clause = {
          '==': clause
        }
      }
      utils.forOwn(clause, (expr, op) => {
        fields.push(field)
        ops.push(op)
        predicates.push(expr)
      })
    })
    return {
github js-data / js-data-mongodb / src / index.js View on Github external
utils.forOwn(query.where, function (criteria, field) {
        if (!utils.isObject(criteria)) {
          query.where[field] = {
            '==': criteria
          }
        }
        utils.forOwn(criteria, function (v, op) {
          if (op === '==' || op === '===' || op === 'contains') {
            mongoQuery[field] = v
          } else if (op === '!=' || op === '!==' || op === 'notContains') {
            mongoQuery[field] = mongoQuery[field] || {}
            mongoQuery[field].$ne = v
          } else if (op === '>') {
            mongoQuery[field] = mongoQuery[field] || {}
            mongoQuery[field].$gt = v
          } else if (op === '>=') {
            mongoQuery[field] = mongoQuery[field] || {}
            mongoQuery[field].$gte = v
          } else if (op === '<') {
            mongoQuery[field] = mongoQuery[field] || {}
            mongoQuery[field].$lt = v
          } else if (op === '<=') {
            mongoQuery[field] = mongoQuery[field] || {}