Skip to content

Commit 65b5536

Browse files
committed
Support user parameters
1 parent 8282fd3 commit 65b5536

File tree

7 files changed

+614
-428
lines changed

7 files changed

+614
-428
lines changed

packages/sync-rules/src/sql_filters.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -277,30 +277,7 @@ export class SqlTools {
277277
// 1. row value = row value
278278
return compileStaticOperator(op, leftFilter as RowValueClause, rightFilter as RowValueClause);
279279
} else if (isParameterValueClause(otherFilter)) {
280-
// 2. row value = parameter value
281-
const inputParam = this.basicInputParameter(otherFilter);
282-
283-
return {
284-
error: false,
285-
inputParameters: [inputParam],
286-
unbounded: false,
287-
filterRow(tables: QueryParameters): TrueIfParametersMatch {
288-
const value = staticFilter.evaluate(tables);
289-
if (value == null) {
290-
// null never matches on =
291-
// Should technically return null, but "false" is sufficient here
292-
return MATCH_CONST_FALSE;
293-
}
294-
if (!isJsonValue(value)) {
295-
// Cannot persist this, e.g. BLOB
296-
return MATCH_CONST_FALSE;
297-
}
298-
299-
return [{ [inputParam.key]: value }];
300-
},
301-
usesAuthenticatedRequestParameters: otherFilter.usesAuthenticatedRequestParameters,
302-
usesUnauthenticatedRequestParameters: otherFilter.usesUnauthenticatedRequestParameters
303-
} satisfies ParameterMatchClause;
280+
return this.parameterMatchClause(staticFilter, otherFilter);
304281
} else if (isParameterMatchClause(otherFilter)) {
305282
// 3. row value = parameterMatch
306283
// (bucket.param = 'something') = staticValue
@@ -489,6 +466,32 @@ export class SqlTools {
489466
}
490467
}
491468

469+
parameterMatchClause(staticFilter: RowValueClause, otherFilter: ParameterValueClause) {
470+
const inputParam = this.basicInputParameter(otherFilter);
471+
472+
return {
473+
error: false,
474+
inputParameters: [inputParam],
475+
unbounded: false,
476+
filterRow(tables: QueryParameters): TrueIfParametersMatch {
477+
const value = staticFilter.evaluate(tables);
478+
if (value == null) {
479+
// null never matches on =
480+
// Should technically return null, but "false" is sufficient here
481+
return MATCH_CONST_FALSE;
482+
}
483+
if (!isJsonValue(value)) {
484+
// Cannot persist this, e.g. BLOB
485+
return MATCH_CONST_FALSE;
486+
}
487+
488+
return [{ [inputParam.key]: value }];
489+
},
490+
usesAuthenticatedRequestParameters: otherFilter.usesAuthenticatedRequestParameters,
491+
usesUnauthenticatedRequestParameters: otherFilter.usesUnauthenticatedRequestParameters
492+
} satisfies ParameterMatchClause;
493+
}
494+
492495
/**
493496
* "some_column" => "some_column"
494497
* "table.some_column" => "some_column".

0 commit comments

Comments
 (0)