Skip to content

Commit

Permalink
allow chaining filterWhere/where for AND conditions in DataSync JS API
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyj0 committed Feb 7, 2022
1 parent d776935 commit 051a9fd
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/IHP/DataSync/ihp-querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class QueryBuilder {
this.transactionId = null;
}

#addWhereCondition(operator, conditionExpression) {
if (this.query.whereCondition === null) {
this.query.whereCondition = conditionExpression;
} else {
this.query.whereCondition = { tag: 'InfixOperatorExpression', this.query.whereCondition, operator, conditionExpression };
}
}

where() {
return this.filterWhere.apply(this, Array.from(arguments))
}
Expand All @@ -38,11 +46,22 @@ class QueryBuilder {
const left = { tag: 'ColumnExpression', field };
const op = 'OpEqual';
const right = { tag: 'LiteralExpression', value: jsValueToDynamicValue(value) }
this.query.whereCondition = { tag: 'InfixOperatorExpression', left, op, right };
const conditionExpression = { tag: 'InfixOperatorExpression', left, op, right }
this.#addWhereCondition('OpAnd', conditionExpression)

return this;
}

filterWhereNot(field, value) {
const left = { tag: 'ColumnExpression', field }
const op = 'OpNotEqual'
const right = { tag: 'LiteralExpression', value: jsValueToDynamicValue(value) }
const conditionExpression = { tag: 'InfixOperatorExpression', value: jsValueToDynamicValue(value) }
this.#addWhereCondition('OpAnd', conditionExpression)

return this;
}

orderBy(column) {
return this.orderByAsc(column);
}
Expand Down

0 comments on commit 051a9fd

Please sign in to comment.