Skip to content

Commit

Permalink
Support types besides strings in DataSync's filterWhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Dec 29, 2021
1 parent 3d727b1 commit e637f8c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/IHP/DataSync/ihp-querybuilder.js
Expand Up @@ -32,7 +32,7 @@ class QueryBuilder {
filterWhere(field, value) {
const left = { tag: 'ColumnExpression', field };
const op = 'OpEqual';
const right = { tag: 'LiteralExpression', value: { tag: 'TextValue', contents: value } }
const right = { tag: 'LiteralExpression', value: jsValueToDynamicValue(value) }
this.query.whereCondition = { tag: 'InfixOperatorExpression', left, op, right };

return this;
Expand Down Expand Up @@ -82,4 +82,18 @@ function query(table) {
return new QueryBuilder(table);
}

function jsValueToDynamicValue(value) {
if (typeof value === "string") {
return { tag: 'TextValue', contents: value };
} else if (typeof value === "number") {
return { tag: 'IntValue', contents: value };
} else if (typeof value === "boolean") {
return { tag: 'BoolValue', contents: value };
} else if (value === null || value === undefined) {
return { tag: 'NullValue' };
}

throw new Error('Could no transform JS value to DynamicValue');
}

export { QueryBuilder, query, ihpBackendUrl, fetchAuthenticated };

0 comments on commit e637f8c

Please sign in to comment.