UNPKG

@warlock.js/cascade

Version:

ORM for managing databases

64 lines (63 loc) 1.96 kB
import {WhereExpression}from'./WhereExpression.js';import {WherePipeline}from'./WherePipeline.js';class OrWherePipeline extends WherePipeline { constructor(expression) { super(expression); } /** * {@inheritDoc} */ parse() { const data = []; // we have three types of where // first one is an array of arrays, each array contains two items, column and value // second one is an array of objects, each object contains column and value // third one is an object, each key is the column and the value is the value (Recommended for simple multiple value checks) /** * Examples * * Example 1: * query.orWhere([ * ["name", "hasan"], * ["age", 20] * ]) * * Example 2 * query.orWhere([ * {bedrooms: $agg.in([20, 30, 40])}, * {bedrooms: $agg.gte(7)} * ]) * * Example 3 * query.orWhere({ * name: "hasan", * age: 20 * }) */ if (Array.isArray(this.pipelineData)) { for (const operation of this.pipelineData) { if (Array.isArray(operation)) { data.push({ [operation[0]]: operation[1], }); } else { data.push(operation); } } } else { for (const column in this.pipelineData) { data.push({ [column]: this.pipelineData[column], }); } } return { $match: { $or: data, }, }; } } function orWherePipeline(...args) { return new OrWherePipeline(WhereExpression.parse.apply(null, args)); }export{OrWherePipeline,orWherePipeline};//# sourceMappingURL=OrWherePipeline.js.map