@powersync/service-sync-rules 0.29.9 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseSqlDataQuery.d.ts +3 -9
- package/dist/BaseSqlDataQuery.js +11 -21
- package/dist/BaseSqlDataQuery.js.map +1 -1
- package/dist/BucketParameterQuerier.d.ts +42 -9
- package/dist/BucketParameterQuerier.js +30 -7
- package/dist/BucketParameterQuerier.js.map +1 -1
- package/dist/BucketSource.d.ts +94 -25
- package/dist/BucketSource.js +67 -0
- package/dist/BucketSource.js.map +1 -1
- package/dist/ExpressionType.d.ts +4 -2
- package/dist/ExpressionType.js.map +1 -1
- package/dist/HydratedSyncRules.d.ts +46 -0
- package/dist/HydratedSyncRules.js +88 -0
- package/dist/HydratedSyncRules.js.map +1 -0
- package/dist/HydrationState.d.ts +45 -0
- package/dist/HydrationState.js +41 -0
- package/dist/HydrationState.js.map +1 -0
- package/dist/SqlBucketDescriptor.d.ts +31 -28
- package/dist/SqlBucketDescriptor.js +89 -112
- package/dist/SqlBucketDescriptor.js.map +1 -1
- package/dist/SqlDataQuery.d.ts +4 -4
- package/dist/SqlDataQuery.js +5 -6
- package/dist/SqlDataQuery.js.map +1 -1
- package/dist/SqlParameterQuery.d.ts +17 -9
- package/dist/SqlParameterQuery.js +49 -23
- package/dist/SqlParameterQuery.js.map +1 -1
- package/dist/SqlSyncRules.d.ts +13 -29
- package/dist/SqlSyncRules.js +48 -77
- package/dist/SqlSyncRules.js.map +1 -1
- package/dist/StaticSqlParameterQuery.d.ts +13 -3
- package/dist/StaticSqlParameterQuery.js +38 -4
- package/dist/StaticSqlParameterQuery.js.map +1 -1
- package/dist/TablePattern.d.ts +4 -1
- package/dist/TablePattern.js +11 -0
- package/dist/TablePattern.js.map +1 -1
- package/dist/TableValuedFunctionSqlParameterQuery.d.ts +14 -4
- package/dist/TableValuedFunctionSqlParameterQuery.js +41 -7
- package/dist/TableValuedFunctionSqlParameterQuery.js.map +1 -1
- package/dist/compatibility.d.ts +23 -1
- package/dist/compatibility.js +32 -4
- package/dist/compatibility.js.map +1 -1
- package/dist/compiler/bucket_resolver.d.ts +70 -0
- package/dist/compiler/bucket_resolver.js +131 -0
- package/dist/compiler/bucket_resolver.js.map +1 -0
- package/dist/compiler/compatibility.d.ts +16 -0
- package/dist/compiler/compatibility.js +12 -0
- package/dist/compiler/compatibility.js.map +1 -0
- package/dist/compiler/compiler.d.ts +104 -0
- package/dist/compiler/compiler.js +113 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/equality.d.ts +99 -0
- package/dist/compiler/equality.js +284 -0
- package/dist/compiler/equality.js.map +1 -0
- package/dist/compiler/expression.d.ts +77 -0
- package/dist/compiler/expression.js +122 -0
- package/dist/compiler/expression.js.map +1 -0
- package/dist/compiler/filter.d.ts +71 -0
- package/dist/compiler/filter.js +110 -0
- package/dist/compiler/filter.js.map +1 -0
- package/dist/compiler/filter_simplifier.d.ts +26 -0
- package/dist/compiler/filter_simplifier.js +119 -0
- package/dist/compiler/filter_simplifier.js.map +1 -0
- package/dist/compiler/ir_to_sync_plan.d.ts +37 -0
- package/dist/compiler/ir_to_sync_plan.js +163 -0
- package/dist/compiler/ir_to_sync_plan.js.map +1 -0
- package/dist/compiler/parser.d.ts +99 -0
- package/dist/compiler/parser.js +556 -0
- package/dist/compiler/parser.js.map +1 -0
- package/dist/compiler/querier_graph.d.ts +42 -0
- package/dist/compiler/querier_graph.js +365 -0
- package/dist/compiler/querier_graph.js.map +1 -0
- package/dist/compiler/rows.d.ts +113 -0
- package/dist/compiler/rows.js +156 -0
- package/dist/compiler/rows.js.map +1 -0
- package/dist/compiler/scope.d.ts +22 -0
- package/dist/compiler/scope.js +47 -0
- package/dist/compiler/scope.js.map +1 -0
- package/dist/compiler/sqlite.d.ts +77 -0
- package/dist/compiler/sqlite.js +412 -0
- package/dist/compiler/sqlite.js.map +1 -0
- package/dist/compiler/table.d.ts +67 -0
- package/dist/compiler/table.js +67 -0
- package/dist/compiler/table.js.map +1 -0
- package/dist/errors.d.ts +4 -2
- package/dist/errors.js +16 -1
- package/dist/errors.js.map +1 -1
- package/dist/events/SqlEventDescriptor.js +1 -1
- package/dist/events/SqlEventDescriptor.js.map +1 -1
- package/dist/events/SqlEventSourceQuery.d.ts +1 -1
- package/dist/events/SqlEventSourceQuery.js +1 -2
- package/dist/events/SqlEventSourceQuery.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/json_schema.js +5 -1
- package/dist/json_schema.js.map +1 -1
- package/dist/request_functions.js +1 -1
- package/dist/request_functions.js.map +1 -1
- package/dist/schema-generators/SchemaGenerator.d.ts +5 -0
- package/dist/schema-generators/SchemaGenerator.js +21 -14
- package/dist/schema-generators/SchemaGenerator.js.map +1 -1
- package/dist/sql_functions.d.ts +2 -1
- package/dist/sql_functions.js +1 -1
- package/dist/sql_functions.js.map +1 -1
- package/dist/streams/filter.d.ts +34 -4
- package/dist/streams/filter.js +93 -23
- package/dist/streams/filter.js.map +1 -1
- package/dist/streams/from_sql.js +2 -5
- package/dist/streams/from_sql.js.map +1 -1
- package/dist/streams/parameter.d.ts +7 -6
- package/dist/streams/stream.d.ts +25 -15
- package/dist/streams/stream.js +59 -87
- package/dist/streams/stream.js.map +1 -1
- package/dist/streams/variant.d.ts +14 -21
- package/dist/streams/variant.js +68 -46
- package/dist/streams/variant.js.map +1 -1
- package/dist/sync_plan/engine/javascript.d.ts +6 -0
- package/dist/sync_plan/engine/javascript.js +208 -0
- package/dist/sync_plan/engine/javascript.js.map +1 -0
- package/dist/sync_plan/engine/scalar_expression_engine.d.ts +48 -0
- package/dist/sync_plan/engine/scalar_expression_engine.js +99 -0
- package/dist/sync_plan/engine/scalar_expression_engine.js.map +1 -0
- package/dist/sync_plan/engine/sqlite.d.ts +12 -0
- package/dist/sync_plan/engine/sqlite.js +53 -0
- package/dist/sync_plan/engine/sqlite.js.map +1 -0
- package/dist/sync_plan/evaluator/bucket_data_source.d.ts +23 -0
- package/dist/sync_plan/evaluator/bucket_data_source.js +137 -0
- package/dist/sync_plan/evaluator/bucket_data_source.js.map +1 -0
- package/dist/sync_plan/evaluator/bucket_source.d.ts +19 -0
- package/dist/sync_plan/evaluator/bucket_source.js +145 -0
- package/dist/sync_plan/evaluator/bucket_source.js.map +1 -0
- package/dist/sync_plan/evaluator/index.d.ts +7 -0
- package/dist/sync_plan/evaluator/index.js +26 -0
- package/dist/sync_plan/evaluator/index.js.map +1 -0
- package/dist/sync_plan/evaluator/parameter_evaluator.d.ts +138 -0
- package/dist/sync_plan/evaluator/parameter_evaluator.js +359 -0
- package/dist/sync_plan/evaluator/parameter_evaluator.js.map +1 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.d.ts +19 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js +62 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js.map +1 -0
- package/dist/sync_plan/expression.d.ts +109 -0
- package/dist/sync_plan/expression.js +85 -0
- package/dist/sync_plan/expression.js.map +1 -0
- package/dist/sync_plan/expression_to_sql.d.ts +43 -0
- package/dist/sync_plan/expression_to_sql.js +190 -0
- package/dist/sync_plan/expression_to_sql.js.map +1 -0
- package/dist/sync_plan/expression_visitor.d.ts +57 -0
- package/dist/sync_plan/expression_visitor.js +181 -0
- package/dist/sync_plan/expression_visitor.js.map +1 -0
- package/dist/sync_plan/plan.d.ts +196 -0
- package/dist/sync_plan/plan.js +2 -0
- package/dist/sync_plan/plan.js.map +1 -0
- package/dist/sync_plan/schema_inference.d.ts +15 -0
- package/dist/sync_plan/schema_inference.js +121 -0
- package/dist/sync_plan/schema_inference.js.map +1 -0
- package/dist/sync_plan/serialize.d.ts +82 -0
- package/dist/sync_plan/serialize.js +209 -0
- package/dist/sync_plan/serialize.js.map +1 -0
- package/dist/types/custom_sqlite_value.d.ts +1 -1
- package/dist/types/time.d.ts +24 -5
- package/dist/types/time.js +67 -12
- package/dist/types/time.js.map +1 -1
- package/dist/types.d.ts +52 -24
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +9 -2
- package/dist/utils.js +26 -3
- package/dist/utils.js.map +1 -1
- package/package.json +4 -3
- package/schema/sync_rules.json +9 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An enumeration of all scalar SQL expressions supported by the sync service.
|
|
3
|
+
*
|
|
4
|
+
* Note that these expressions can be serialized, and the evaluation of serialized expressions must be stable.
|
|
5
|
+
*
|
|
6
|
+
* The `Data` type parameter encodes what external data references an {@link ExternalData} node may reference: Bucket
|
|
7
|
+
* data sources can only reference row data (e.g. to evaluate filters), while queriers can only reference connection
|
|
8
|
+
* data. Adding the parameter to expressions ensures the entire subtree can only reference expected sources.
|
|
9
|
+
*/
|
|
10
|
+
export type SqlExpression<Data> = ExternalData<Data> | UnaryExpression<Data> | BinaryExpression<Data> | BetweenExpression<Data> | ScalarInExpression<Data> | CaseWhenExpression<Data> | CastExpression<Data> | ScalarFunctionCallExpression<Data> | LiteralExpression;
|
|
11
|
+
/**
|
|
12
|
+
* External data injected into the expression during evaluation.
|
|
13
|
+
*
|
|
14
|
+
* What kinds of external data is allowed depends on the expression. For instance, expressions for bucket data sources
|
|
15
|
+
* may only reference columns in the current row.
|
|
16
|
+
*/
|
|
17
|
+
export type ExternalData<Data> = {
|
|
18
|
+
type: 'data';
|
|
19
|
+
source: Data;
|
|
20
|
+
};
|
|
21
|
+
export type UnaryOperator = 'not' | '+';
|
|
22
|
+
export type UnaryExpression<Data> = {
|
|
23
|
+
type: 'unary';
|
|
24
|
+
operand: SqlExpression<Data>;
|
|
25
|
+
operator: UnaryOperator;
|
|
26
|
+
};
|
|
27
|
+
export type BinaryOperator = 'or' | 'and' | '=' | 'is' | '<' | '<=' | '>' | '>=' | '&' | '|' | '<<' | '>>' | '+' | '-' | '*' | '/' | '%' | '||';
|
|
28
|
+
/**
|
|
29
|
+
* A binary expression in SQLite, `$left $op $right`.
|
|
30
|
+
*
|
|
31
|
+
* Note that the `LIKE`, `GLOB`, `REGEXP` and `MATCH`, `->` and `->>` operators are not represented as binary
|
|
32
|
+
* expressions but rather as the functions SQLite [would call for them](https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators).
|
|
33
|
+
* Also, note that negated operators (e.g. `!=` or `NOT IN`) are represented by wrapping the expression in a unary
|
|
34
|
+
* `NOT`. This makes transformations to DNF easier.
|
|
35
|
+
*/
|
|
36
|
+
export type BinaryExpression<Data> = {
|
|
37
|
+
type: 'binary';
|
|
38
|
+
left: SqlExpression<Data>;
|
|
39
|
+
operator: BinaryOperator;
|
|
40
|
+
right: SqlExpression<Data>;
|
|
41
|
+
};
|
|
42
|
+
export type BetweenExpression<Data> = {
|
|
43
|
+
type: 'between';
|
|
44
|
+
value: SqlExpression<Data>;
|
|
45
|
+
low: SqlExpression<Data>;
|
|
46
|
+
high: SqlExpression<Data>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* An `expr IN ($in0, $in1, ..., $inN)` expression.
|
|
50
|
+
*/
|
|
51
|
+
export type ScalarInExpression<Data> = {
|
|
52
|
+
type: 'scalar_in';
|
|
53
|
+
target: SqlExpression<Data>;
|
|
54
|
+
in: SqlExpression<Data>[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* A `CASE WHEN` expression as supported by SQLite.
|
|
58
|
+
*/
|
|
59
|
+
export type CaseWhenExpression<Data> = {
|
|
60
|
+
type: 'case_when';
|
|
61
|
+
operand?: SqlExpression<Data>;
|
|
62
|
+
whens: {
|
|
63
|
+
when: SqlExpression<Data>;
|
|
64
|
+
then: SqlExpression<Data>;
|
|
65
|
+
}[];
|
|
66
|
+
else?: SqlExpression<Data>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A `CAST` expression.
|
|
70
|
+
*/
|
|
71
|
+
export type CastExpression<Data> = {
|
|
72
|
+
type: 'cast';
|
|
73
|
+
operand: SqlExpression<Data>;
|
|
74
|
+
cast_as: 'text' | 'numeric' | 'real' | 'integer' | 'blob';
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A constant literal in SQL.
|
|
78
|
+
*/
|
|
79
|
+
export type LiteralExpression = {
|
|
80
|
+
type: 'lit_null';
|
|
81
|
+
} | {
|
|
82
|
+
type: 'lit_double';
|
|
83
|
+
value: number;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'lit_int';
|
|
86
|
+
/**
|
|
87
|
+
* The integer value as a base 10 string. We don't use the correct `bigint` type to be able to serialize and
|
|
88
|
+
* deserialize with the default JSON implementation.
|
|
89
|
+
*/
|
|
90
|
+
base10: string;
|
|
91
|
+
} | {
|
|
92
|
+
type: 'lit_string';
|
|
93
|
+
value: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A scalar (non-aggregate, non-window, non-table-valued) function call in SQL.
|
|
97
|
+
*/
|
|
98
|
+
export type ScalarFunctionCallExpression<Data> = {
|
|
99
|
+
type: 'function';
|
|
100
|
+
function: string;
|
|
101
|
+
parameters: SqlExpression<Data>[];
|
|
102
|
+
};
|
|
103
|
+
export type ArgumentCount = number | {
|
|
104
|
+
min: number;
|
|
105
|
+
max?: number;
|
|
106
|
+
mustBeEven?: boolean;
|
|
107
|
+
mustBeOdd?: boolean;
|
|
108
|
+
};
|
|
109
|
+
export declare const supportedFunctions: Record<string, ArgumentCount>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export const supportedFunctions = {
|
|
2
|
+
// https://sqlite.org/lang_corefunc.html#list_of_core_functions
|
|
3
|
+
abs: 1,
|
|
4
|
+
char: { min: 0 },
|
|
5
|
+
coalesce: { min: 2 },
|
|
6
|
+
concat: { min: 1 },
|
|
7
|
+
concat_ws: { min: 2 },
|
|
8
|
+
format: { min: 1 },
|
|
9
|
+
glob: 2,
|
|
10
|
+
hex: 1,
|
|
11
|
+
ifnull: { min: 2 },
|
|
12
|
+
if: { min: 2 },
|
|
13
|
+
iif: { min: 2 },
|
|
14
|
+
instr: 2,
|
|
15
|
+
length: 1,
|
|
16
|
+
// TODO: Establish defaults for case sensitivity, changing escape characters, ICU support.
|
|
17
|
+
// We might just want to remove LIKE support since we don't seem to have it in sql_functions.ts
|
|
18
|
+
like: { min: 2, max: 3 },
|
|
19
|
+
// likelihood: 2,
|
|
20
|
+
// likely: 1,
|
|
21
|
+
lower: 1,
|
|
22
|
+
ltrim: { min: 1, max: 2 },
|
|
23
|
+
max: { min: 2 },
|
|
24
|
+
min: { min: 2 },
|
|
25
|
+
nullif: 2,
|
|
26
|
+
octet_length: 1,
|
|
27
|
+
printf: { min: 1 },
|
|
28
|
+
quote: 1,
|
|
29
|
+
replace: 3,
|
|
30
|
+
round: { min: 1, max: 2 },
|
|
31
|
+
rtrim: { min: 1, max: 2 },
|
|
32
|
+
sign: 1,
|
|
33
|
+
substr: { min: 2, max: 3 },
|
|
34
|
+
substring: { min: 2, max: 3 },
|
|
35
|
+
trim: { min: 1, max: 2 },
|
|
36
|
+
typeof: 1,
|
|
37
|
+
unhex: { min: 1, max: 2 },
|
|
38
|
+
unicode: 1,
|
|
39
|
+
unistr: 1,
|
|
40
|
+
unistr_quote: 1,
|
|
41
|
+
// unlikely: 1,
|
|
42
|
+
upper: 1,
|
|
43
|
+
zeroblob: 1,
|
|
44
|
+
// Scalar functions from https://sqlite.org/json1.html#overview
|
|
45
|
+
// We disallow jsonb functions because they're not implemented in sql_functions.ts and we want to preserve
|
|
46
|
+
// compatibility with that.
|
|
47
|
+
json: 1,
|
|
48
|
+
// jsonb: 1,
|
|
49
|
+
json_array: { min: 0 },
|
|
50
|
+
// jsonb_array: { min: 0 },
|
|
51
|
+
json_array_length: { min: 1, max: 2 },
|
|
52
|
+
json_error_position: 1,
|
|
53
|
+
json_extract: { min: 2 },
|
|
54
|
+
// jsonb_extract: { min: 2 },
|
|
55
|
+
json_insert: { min: 3, mustBeOdd: true },
|
|
56
|
+
// jsonb_insert: { min: 3, mustBeOdd: true },
|
|
57
|
+
json_object: { min: 0, mustBeEven: true },
|
|
58
|
+
// jsonb_object: { min: 0, mustBeEven: true },
|
|
59
|
+
json_patch: 2,
|
|
60
|
+
// jsonb_patch: 2,
|
|
61
|
+
json_pretty: 1,
|
|
62
|
+
json_remove: { min: 2 },
|
|
63
|
+
// jsonb_remove: { min: 2 },
|
|
64
|
+
json_replace: { min: 3, mustBeOdd: true },
|
|
65
|
+
// jsonb_replace: { min: 3, mustBeOdd: true },
|
|
66
|
+
json_set: { min: 3, mustBeOdd: true },
|
|
67
|
+
// jsonb_set: { min: 3, mustBeOdd: true },
|
|
68
|
+
json_type: { min: 1, max: 2 },
|
|
69
|
+
json_valid: { min: 1, max: 2 },
|
|
70
|
+
json_quote: { min: 1 },
|
|
71
|
+
// https://www.sqlite.org/lang_datefunc.html, but we only support datetime and unixepoch
|
|
72
|
+
// TODO: Ensure our support matches the current unixepoch behavior in sql_functions.ts, register as user-defined
|
|
73
|
+
// function to patch default if in doubt.
|
|
74
|
+
unixepoch: { min: 1 },
|
|
75
|
+
datetime: { min: 1 },
|
|
76
|
+
// PowerSync-specific, mentioned in https://docs.powersync.com/sync/rules/supported-sql#functions
|
|
77
|
+
base64: 1,
|
|
78
|
+
json_keys: 1,
|
|
79
|
+
uuid_blob: 1,
|
|
80
|
+
st_asgeojson: 1,
|
|
81
|
+
st_astext: 1,
|
|
82
|
+
st_x: 1,
|
|
83
|
+
st_y: 1
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/sync_plan/expression.ts"],"names":[],"mappings":"AAqIA,MAAM,CAAC,MAAM,kBAAkB,GAAkC;IAC/D,+DAA+D;IAC/D,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;IAChB,QAAQ,EAAE,EAAE,G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;IACxF,gHAAgH;IAChH,yCAAyC;IACzC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;IACrB,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;IAEpB,iGAAiG;IACjG,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,YAAY,EAAE,CAAC;IACf,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BetweenExpression, BinaryExpression, CaseWhenExpression, CastExpression, ExternalData, LiteralExpression, ScalarFunctionCallExpression, ScalarInExpression, SqlExpression, UnaryExpression } from './expression.js';
|
|
2
|
+
import { ExpressionVisitor } from './expression_visitor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders {@link SqlExpression}s into SQL text supported by SQLite.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ExpressionToSqlite<Data> implements ExpressionVisitor<Data, void, Precedence | 0> {
|
|
7
|
+
sql: string;
|
|
8
|
+
private needsSpace;
|
|
9
|
+
addExpression(expr: SqlExpression<Data>, precedence?: Precedence | 0): void;
|
|
10
|
+
private space;
|
|
11
|
+
addLexeme(text: string, options?: {
|
|
12
|
+
spaceLeft?: boolean;
|
|
13
|
+
spaceRight?: boolean;
|
|
14
|
+
}): number;
|
|
15
|
+
identifier(name: string): void;
|
|
16
|
+
private string;
|
|
17
|
+
private commaSeparated;
|
|
18
|
+
private parenthesis;
|
|
19
|
+
private maybeParenthesis;
|
|
20
|
+
visitExternalData(_expr: ExternalData<Data>): void;
|
|
21
|
+
visitUnaryExpression(expr: UnaryExpression<Data>, outerPrecedence: Precedence | 0): void;
|
|
22
|
+
visitBinaryExpression(expr: BinaryExpression<Data>, outerPrecedence: Precedence | 0): void;
|
|
23
|
+
visitBetweenExpression(expr: BetweenExpression<Data>, outerPrecedence: 0 | Precedence): void;
|
|
24
|
+
visitScalarInExpression(expr: ScalarInExpression<Data>, arg: Precedence | 0): void;
|
|
25
|
+
visitCaseWhenExpression(expr: CaseWhenExpression<Data>, arg: Precedence | 0): void;
|
|
26
|
+
visitCastExpression(expr: CastExpression<Data>, arg: Precedence | 0): void;
|
|
27
|
+
visitScalarFunctionCallExpression(expr: ScalarFunctionCallExpression<Data>, arg: Precedence | 0): void;
|
|
28
|
+
visitLiteralExpression(expr: LiteralExpression, arg: Precedence | 0): void;
|
|
29
|
+
static toSqlite(expr: SqlExpression<unknown>): string;
|
|
30
|
+
}
|
|
31
|
+
export declare enum Precedence {
|
|
32
|
+
or = 1,
|
|
33
|
+
and = 2,
|
|
34
|
+
not = 3,
|
|
35
|
+
equals = 4,
|
|
36
|
+
comparison = 5,
|
|
37
|
+
binary = 6,
|
|
38
|
+
addition = 7,
|
|
39
|
+
multiplication = 8,
|
|
40
|
+
concat = 9,
|
|
41
|
+
collate = 10,
|
|
42
|
+
unary = 11
|
|
43
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { visitExpr } from './expression_visitor.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renders {@link SqlExpression}s into SQL text supported by SQLite.
|
|
4
|
+
*/
|
|
5
|
+
export class ExpressionToSqlite {
|
|
6
|
+
sql = '';
|
|
7
|
+
needsSpace = false;
|
|
8
|
+
addExpression(expr, precedence = 0) {
|
|
9
|
+
visitExpr(this, expr, precedence);
|
|
10
|
+
}
|
|
11
|
+
space() {
|
|
12
|
+
this.sql += ' ';
|
|
13
|
+
}
|
|
14
|
+
addLexeme(text, options) {
|
|
15
|
+
const spaceLeft = options?.spaceLeft ?? true;
|
|
16
|
+
const spaceRight = options?.spaceRight ?? true;
|
|
17
|
+
if (this.needsSpace && spaceLeft) {
|
|
18
|
+
this.space();
|
|
19
|
+
}
|
|
20
|
+
const startOffset = this.sql.length;
|
|
21
|
+
this.sql += text;
|
|
22
|
+
this.needsSpace = spaceRight;
|
|
23
|
+
return startOffset;
|
|
24
|
+
}
|
|
25
|
+
identifier(name) {
|
|
26
|
+
this.addLexeme(`"${name.replaceAll('"', '""')}"`);
|
|
27
|
+
}
|
|
28
|
+
string(name) {
|
|
29
|
+
this.addLexeme(`'${name.replaceAll("'", "''")}'`);
|
|
30
|
+
}
|
|
31
|
+
commaSeparated(exprList) {
|
|
32
|
+
let first = true;
|
|
33
|
+
for (const expr of exprList) {
|
|
34
|
+
if (!first) {
|
|
35
|
+
this.addLexeme(',', { spaceLeft: false });
|
|
36
|
+
}
|
|
37
|
+
this.addExpression(expr);
|
|
38
|
+
first = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
parenthesis(inner) {
|
|
42
|
+
this.addLexeme('(', { spaceRight: false });
|
|
43
|
+
inner();
|
|
44
|
+
this.addLexeme(')', { spaceLeft: false });
|
|
45
|
+
}
|
|
46
|
+
maybeParenthesis(outerPrecedence, innerPrecedence, inner) {
|
|
47
|
+
if (outerPrecedence > innerPrecedence) {
|
|
48
|
+
this.parenthesis(inner);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
inner();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
visitExternalData(_expr) {
|
|
55
|
+
this.addLexeme('?');
|
|
56
|
+
}
|
|
57
|
+
visitUnaryExpression(expr, outerPrecedence) {
|
|
58
|
+
const innerPrecedence = unaryPrecedence[expr.operator];
|
|
59
|
+
this.maybeParenthesis(outerPrecedence, innerPrecedence, () => {
|
|
60
|
+
this.addLexeme(expr.operator);
|
|
61
|
+
this.addExpression(expr.operand, innerPrecedence);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
visitBinaryExpression(expr, outerPrecedence) {
|
|
65
|
+
const innerPrecedence = binaryPrecedence[expr.operator];
|
|
66
|
+
this.maybeParenthesis(outerPrecedence, innerPrecedence, () => {
|
|
67
|
+
this.addExpression(expr.left, innerPrecedence);
|
|
68
|
+
this.addLexeme(expr.operator);
|
|
69
|
+
this.addExpression(expr.right, innerPrecedence);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
visitBetweenExpression(expr, outerPrecedence) {
|
|
73
|
+
const innerPrecedence = Precedence.equals;
|
|
74
|
+
this.maybeParenthesis(outerPrecedence, innerPrecedence, () => {
|
|
75
|
+
this.addExpression(expr.value, Precedence.equals);
|
|
76
|
+
this.addLexeme('BETWEEN');
|
|
77
|
+
this.addExpression(expr.low, Precedence.equals);
|
|
78
|
+
this.addLexeme('AND');
|
|
79
|
+
this.addExpression(expr.high, Precedence.equals);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
visitScalarInExpression(expr, arg) {
|
|
83
|
+
if (expr.in.length == 0) {
|
|
84
|
+
// x IN () is invalid, but it can't be true either way.
|
|
85
|
+
this.addLexeme('FALSE');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.maybeParenthesis(arg, Precedence.equals, () => {
|
|
89
|
+
this.addExpression(expr.target, Precedence.equals);
|
|
90
|
+
this.addLexeme('IN');
|
|
91
|
+
this.parenthesis(() => this.commaSeparated(expr.in));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
visitCaseWhenExpression(expr, arg) {
|
|
95
|
+
this.addLexeme('CASE');
|
|
96
|
+
if (expr.operand) {
|
|
97
|
+
this.addExpression(expr.operand);
|
|
98
|
+
}
|
|
99
|
+
for (const when of expr.whens) {
|
|
100
|
+
this.addLexeme('WHEN');
|
|
101
|
+
this.addExpression(when.when);
|
|
102
|
+
this.addLexeme('THEN');
|
|
103
|
+
this.addExpression(when.then);
|
|
104
|
+
}
|
|
105
|
+
if (expr.else) {
|
|
106
|
+
this.addLexeme('ELSE');
|
|
107
|
+
this.addExpression(expr.else);
|
|
108
|
+
}
|
|
109
|
+
this.addLexeme('END');
|
|
110
|
+
}
|
|
111
|
+
visitCastExpression(expr, arg) {
|
|
112
|
+
this.addLexeme('CAST(', { spaceRight: false });
|
|
113
|
+
this.addExpression(expr.operand);
|
|
114
|
+
this.addLexeme('AS');
|
|
115
|
+
this.addLexeme(expr.cast_as);
|
|
116
|
+
this.addLexeme(')', { spaceLeft: false });
|
|
117
|
+
}
|
|
118
|
+
visitScalarFunctionCallExpression(expr, arg) {
|
|
119
|
+
this.identifier(expr.function);
|
|
120
|
+
this.addLexeme('(', { spaceLeft: false, spaceRight: false });
|
|
121
|
+
this.commaSeparated(expr.parameters);
|
|
122
|
+
this.addLexeme(')', { spaceLeft: false });
|
|
123
|
+
}
|
|
124
|
+
visitLiteralExpression(expr, arg) {
|
|
125
|
+
if (expr.type == 'lit_null') {
|
|
126
|
+
this.addLexeme('NULL');
|
|
127
|
+
}
|
|
128
|
+
else if (expr.type == 'lit_double') {
|
|
129
|
+
let lexeme = expr.value.toString();
|
|
130
|
+
if (Number.isInteger(expr.value)) {
|
|
131
|
+
// If we have a double value that happens to be an integer, we still want to treat that as a double in SQLite.
|
|
132
|
+
lexeme += '.0';
|
|
133
|
+
}
|
|
134
|
+
this.addLexeme(lexeme);
|
|
135
|
+
}
|
|
136
|
+
else if (expr.type == 'lit_int') {
|
|
137
|
+
this.addLexeme(expr.base10);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.string(expr.value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
static toSqlite(expr) {
|
|
144
|
+
const visitor = new ExpressionToSqlite();
|
|
145
|
+
visitor.addExpression(expr);
|
|
146
|
+
return visitor.sql;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export var Precedence;
|
|
150
|
+
(function (Precedence) {
|
|
151
|
+
Precedence[Precedence["or"] = 1] = "or";
|
|
152
|
+
Precedence[Precedence["and"] = 2] = "and";
|
|
153
|
+
Precedence[Precedence["not"] = 3] = "not";
|
|
154
|
+
Precedence[Precedence["equals"] = 4] = "equals";
|
|
155
|
+
Precedence[Precedence["comparison"] = 5] = "comparison";
|
|
156
|
+
Precedence[Precedence["binary"] = 6] = "binary";
|
|
157
|
+
Precedence[Precedence["addition"] = 7] = "addition";
|
|
158
|
+
Precedence[Precedence["multiplication"] = 8] = "multiplication";
|
|
159
|
+
Precedence[Precedence["concat"] = 9] = "concat";
|
|
160
|
+
Precedence[Precedence["collate"] = 10] = "collate";
|
|
161
|
+
Precedence[Precedence["unary"] = 11] = "unary";
|
|
162
|
+
})(Precedence || (Precedence = {}));
|
|
163
|
+
// https://www.sqlite.org/lang_expr.html#operators_and_parse_affecting_attributes
|
|
164
|
+
const binaryPrecedence = {
|
|
165
|
+
or: Precedence.or,
|
|
166
|
+
and: Precedence.and,
|
|
167
|
+
'=': Precedence.equals,
|
|
168
|
+
is: Precedence.equals,
|
|
169
|
+
'<': Precedence.comparison,
|
|
170
|
+
'>': Precedence.comparison,
|
|
171
|
+
'<=': Precedence.comparison,
|
|
172
|
+
'>=': Precedence.comparison,
|
|
173
|
+
'&': Precedence.binary,
|
|
174
|
+
'|': Precedence.binary,
|
|
175
|
+
'<<': Precedence.binary,
|
|
176
|
+
'>>': Precedence.binary,
|
|
177
|
+
'+': Precedence.addition,
|
|
178
|
+
'-': Precedence.addition,
|
|
179
|
+
'*': Precedence.multiplication,
|
|
180
|
+
'/': Precedence.multiplication,
|
|
181
|
+
'%': Precedence.multiplication,
|
|
182
|
+
'||': Precedence.concat
|
|
183
|
+
};
|
|
184
|
+
const unaryPrecedence = {
|
|
185
|
+
not: Precedence.not,
|
|
186
|
+
//'~': Precedence.unary,
|
|
187
|
+
'+': Precedence.unary
|
|
188
|
+
//'-': Precedence.unary
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=expression_to_sql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression_to_sql.js","sourceRoot":"","sources":["../../src/sync_plan/expression_to_sql.ts"],"names":[],"mappings":"AAcA,OAAO,EAAqB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEvE;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC7B,GAAG,GAAG,EAAE,CAAC;IAED,UAAU,GAAG,KAA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ACV,mDAAY,CAAA;IACZ,+DAAkB,CAAA;IAClB,+CAAU,CAAA;IACV,kDAAY,CAAA;IACZ,8CAAU,CAAA;AACZ,CAAC,EAZW,UAAU,KAAV,UAAU,QAYrB;AAED,iFAAiF;AACjF,MAAM,gBAAgB,GAAuC;IAC3D,EAAE,EAAE,UAAU,CAAC,EAAE;IACjB,GAAG,EAAE,UAAU,CAAC,GAAG;IACnB,GAAG,EAAE,UAAU,CAAC,MAAM;IACtB,EAAE,EAAE,UAAU,CAAC,MAAM;IACrB,GAAG,EAAE,UAAU,CAAC,UAAU;IAC1B,GAAG,EAAE,UAAU,CAAC,UAAU;IAC1B,IAAI,EAAE,UAAU,CAAC,UAAU;IAC3B,IAAI,EAAE,UAAU,CAAC,UAAU;IAC3B,GAAG,EAAE,UAAU,CAAC,MAAM;IACtB,GAAG,EAAE,UAAU,CAAC,MAAM;IACtB,IAAI,EAAE,UAAU,CAAC,MAAM;IACvB,IAAI,EAAE,UAAU,CAAC,MAAM;IACvB,GAAG,EAAE,UAAU,CAAC,QAAQ;IACxB,GAAG,EAAE,UAAU,CAAC,QAAQ;IACxB,GAAG,EAAE,UAAU,CAAC,cAAc;IAC9B,GAAG,EAAE,UAAU,CAAC,cAAc;IAC9B,GAAG,EAAE,UAAU,CAAC,cAAc;IAC9B,IAAI,EAAE,UAAU,CAAC,MAAM;CACxB,CAAC;AAEF,MAAM,eAAe,GAAsC;IACzD,GAAG,EAAE,UAAU,CAAC,GAAG;IACnB,wBAAwB;IACxB,GAAG,EAAE,UAAU,CAAC,KAAK;IACrB,uBAAuB;CACxB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BetweenExpression, BinaryExpression, CaseWhenExpression, CastExpression, ExternalData, LiteralExpression, ScalarFunctionCallExpression, ScalarInExpression, SqlExpression, UnaryExpression } from './expression.js';
|
|
2
|
+
/**
|
|
3
|
+
* Callbacks for each type of SQL expression we support.
|
|
4
|
+
*
|
|
5
|
+
* The {@link visit} function can be used to call the appropriate callback given an expression.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExpressionVisitor<Data, R, Arg = undefined> {
|
|
8
|
+
visitExternalData(expr: ExternalData<Data>, arg: Arg): R;
|
|
9
|
+
visitUnaryExpression(expr: UnaryExpression<Data>, arg: Arg): R;
|
|
10
|
+
visitBinaryExpression(expr: BinaryExpression<Data>, arg: Arg): R;
|
|
11
|
+
visitBetweenExpression(expr: BetweenExpression<Data>, arg: Arg): R;
|
|
12
|
+
visitScalarInExpression(expr: ScalarInExpression<Data>, arg: Arg): R;
|
|
13
|
+
visitCaseWhenExpression(expr: CaseWhenExpression<Data>, arg: Arg): R;
|
|
14
|
+
visitCastExpression(expr: CastExpression<Data>, arg: Arg): R;
|
|
15
|
+
visitScalarFunctionCallExpression(expr: ScalarFunctionCallExpression<Data>, arg: Arg): R;
|
|
16
|
+
visitLiteralExpression(expr: LiteralExpression, arg: Arg): R;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Invokes the appropriate visit method for the given expression.
|
|
20
|
+
*/
|
|
21
|
+
export declare function visitExpr<Data, R, Arg>(visitor: ExpressionVisitor<Data, R, Arg>, expr: SqlExpression<Data>, arg: Arg): R;
|
|
22
|
+
/**
|
|
23
|
+
* A utility for traversing through a {@link SqlExpression} tree.
|
|
24
|
+
*/
|
|
25
|
+
export declare abstract class RecursiveExpressionVisitor<Data, R, Arg = undefined> implements ExpressionVisitor<Data, R, Arg> {
|
|
26
|
+
abstract defaultExpression(expr: SqlExpression<Data>, arg: Arg): R;
|
|
27
|
+
/**
|
|
28
|
+
* Invokes the appropriate visit method for the given expression.
|
|
29
|
+
*/
|
|
30
|
+
visit(expr: SqlExpression<Data>, arg: Arg): R;
|
|
31
|
+
visitChildren(expr: SqlExpression<Data>, arg: Arg): void;
|
|
32
|
+
visitExternalData(expr: ExternalData<Data>, arg: Arg): R;
|
|
33
|
+
visitUnaryExpression(expr: UnaryExpression<Data>, arg: Arg): R;
|
|
34
|
+
visitBinaryExpression(expr: BinaryExpression<Data>, arg: Arg): R;
|
|
35
|
+
visitBetweenExpression(expr: BetweenExpression<Data>, arg: Arg): R;
|
|
36
|
+
visitScalarInExpression(expr: ScalarInExpression<Data>, arg: Arg): R;
|
|
37
|
+
visitCaseWhenExpression(expr: CaseWhenExpression<Data>, arg: Arg): R;
|
|
38
|
+
visitCastExpression(expr: CastExpression<Data>, arg: Arg): R;
|
|
39
|
+
visitScalarFunctionCallExpression(expr: ScalarFunctionCallExpression<Data>, arg: Arg): R;
|
|
40
|
+
visitLiteralExpression(expr: LiteralExpression, arg: Arg): R;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A visitor applying a mapping function to external data references in expressions.
|
|
44
|
+
*/
|
|
45
|
+
export declare class MapSourceVisitor<DataIn, DataOut> implements ExpressionVisitor<DataIn, SqlExpression<DataOut>> {
|
|
46
|
+
private readonly map;
|
|
47
|
+
constructor(map: (a: DataIn) => DataOut);
|
|
48
|
+
visitExternalData(expr: ExternalData<DataIn>): SqlExpression<DataOut>;
|
|
49
|
+
visitUnaryExpression(expr: UnaryExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
50
|
+
visitBinaryExpression(expr: BinaryExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
51
|
+
visitBetweenExpression(expr: BetweenExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
52
|
+
visitScalarInExpression(expr: ScalarInExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
53
|
+
visitCaseWhenExpression(expr: CaseWhenExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
54
|
+
visitCastExpression(expr: CastExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
55
|
+
visitScalarFunctionCallExpression(expr: ScalarFunctionCallExpression<DataIn>, arg: undefined): SqlExpression<DataOut>;
|
|
56
|
+
visitLiteralExpression(expr: LiteralExpression, arg: undefined): SqlExpression<DataOut>;
|
|
57
|
+
}
|