Example #1
0
  checkValidity: function() {
    var keys = _.intersection(_.keys(CHECKS), _.keys(this.options));

    if (_.isEmpty(keys)) {
      throw new Error('specify the maximum, minimum, or is option');
    }

    _.forEach(keys, function(key) {
      var value = this.options[key];

      if (!_.isNumber(value) || value < 0 || _.isNaN(value)) {
        throw new Error(key + ' must be a nonnegative Integer');
      }
    }, this);
  },
    Object.keys(where).forEach(function(k) {

        // determine if k is field name or condition name
        var conditions = ["and", "or", "between", "gt", "lt", "gte", "lte", "inq", "nin", "near", "neq", "like", "nlike"]
        var condition = where[k]

        if (k === "and" || k === "or") {
            if (_.isArray(condition)) {
                var query = _.map(condition, function(c) {
                    return buildFilter(c)
                })

                if (k === "and")
                    filter.push(_.reduce(query, function(s, f) {
                        return s.and(f)
                    }))
                else
                    filter.push(_.reduce(query, function(s, f) {
                        return s.or(f)
                    }))
            }
        } else {
            if (_.isObject(condition) && _.intersection(_.keys(condition), conditions).length > 0) {
                // k is condition
                _.keys(condition).forEach(function(operator) {
                    if (conditions.indexOf(operator) >= 0) {
                        filter.push(operators[operator](k, condition[operator]))
                    }
                })
            } else {
                // k is field equality
                filter.push(r.row(k).eq(condition))
            }
        }

    })