Skip to content

Commit 8282fd3

Browse files
committed
Support rowvalue IN subquery syntax
1 parent ed3d53d commit 8282fd3

File tree

14 files changed

+1203
-474
lines changed

14 files changed

+1203
-474
lines changed

packages/sync-rules/src/BaseSqlDataQuery.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export interface BaseSqlDataQueryOptions {
3636
descriptorName: string;
3737
bucketParameters: string[];
3838
tools: SqlTools;
39-
4039
errors?: SqlRuleError[];
4140
}
4241

packages/sync-rules/src/SqlBucketDescriptor.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BucketDescription, BucketInclusionReason, ResolvedBucket } from './BucketDescription.js';
1+
import { BucketInclusionReason, ResolvedBucket } from './BucketDescription.js';
22
import { BucketParameterQuerier, mergeBucketParameterQueriers } from './BucketParameterQuerier.js';
33
import { BucketSource, ResultSetDescription } from './BucketSource.js';
44
import { IdSequence } from './IdSequence.js';
@@ -7,7 +7,6 @@ import { SqlDataQuery } from './SqlDataQuery.js';
77
import { SqlParameterQuery } from './SqlParameterQuery.js';
88
import { GetQuerierOptions, SyncRulesOptions } from './SqlSyncRules.js';
99
import { StaticSqlParameterQuery } from './StaticSqlParameterQuery.js';
10-
import { StreamQuery } from './StreamQuery.js';
1110
import { TablePattern } from './TablePattern.js';
1211
import { TableValuedFunctionSqlParameterQuery } from './TableValuedFunctionSqlParameterQuery.js';
1312
import { SqlRuleError } from './errors.js';
@@ -18,8 +17,7 @@ import {
1817
QueryParseOptions,
1918
RequestParameters,
2019
SourceSchema,
21-
SqliteRow,
22-
StreamParseOptions
20+
SqliteRow
2321
} from './types.js';
2422

2523
export interface QueryParseResult {
@@ -96,24 +94,6 @@ export class SqlBucketDescriptor implements BucketSource {
9694
};
9795
}
9896

99-
addUnifiedStreamQuery(sql: string, options: StreamParseOptions): QueryParseResult {
100-
const [query, errors] = StreamQuery.fromSql(this.name, sql, options);
101-
for (const parameterQuery of query.inferredParameters) {
102-
if (parameterQuery instanceof StaticSqlParameterQuery) {
103-
this.globalParameterQueries.push(parameterQuery);
104-
} else {
105-
this.parameterQueries.push(parameterQuery);
106-
}
107-
}
108-
this.dataQueries.push(query.data);
109-
this.subscribedToByDefault = options.default ?? false;
110-
111-
return {
112-
parsed: true,
113-
errors
114-
};
115-
}
116-
11797
evaluateRow(options: EvaluateRowOptions): EvaluationResult[] {
11898
let results: EvaluationResult[] = [];
11999
for (let query of this.dataQueries) {

packages/sync-rules/src/SqlSyncRules.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
SyncRules
2727
} from './types.js';
2828
import { BucketSource } from './BucketSource.js';
29+
import { SyncStream } from './streams/stream.js';
30+
import { syncStreamFromSql } from './streams/from_sql.js';
2931

3032
const ACCEPT_POTENTIALLY_DANGEROUS_QUERIES = Symbol('ACCEPT_POTENTIALLY_DANGEROUS_QUERIES');
3133

@@ -214,8 +216,6 @@ export class SqlSyncRules implements SyncRules {
214216
continue;
215217
}
216218

217-
const descriptor = new SqlBucketDescriptor(key, SqlBucketDescriptorType.STREAM);
218-
219219
const accept_potentially_dangerous_queries =
220220
value.get('accept_potentially_dangerous_queries', true)?.value == true;
221221

@@ -229,14 +229,17 @@ export class SqlSyncRules implements SyncRules {
229229
const data = value.get('query', true) as unknown;
230230
if (data instanceof Scalar) {
231231
rules.withScalar(data, (q) => {
232-
return descriptor.addUnifiedStreamQuery(q, queryOptions);
232+
const [parsed, errors] = syncStreamFromSql(key, q, options);
233+
rules.bucketSources.push(parsed);
234+
return {
235+
parsed: true,
236+
errors
237+
};
233238
});
234239
} else {
235240
rules.errors.push(this.tokenError(data, 'Must be a string.'));
236241
continue;
237242
}
238-
239-
rules.bucketSources.push(descriptor);
240243
}
241244

242245
const eventMap = parsed.get('event_definitions') as YAMLMap;

packages/sync-rules/src/StreamQuery.ts

Lines changed: 0 additions & 191 deletions
This file was deleted.

packages/sync-rules/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './SqlParameterQuery.js';
1818
export * from './SqlSyncRules.js';
1919
export * from './StaticSchema.js';
2020
export { SyncStream } from './streams/stream.js';
21+
export { syncStreamFromSql } from './streams/from_sql.js';
2122
export * from './TablePattern.js';
2223
export * from './types.js';
2324
export * from './utils.js';

packages/sync-rules/src/request_functions.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const request_parameters: SqlParameterFunction = {
2828
usesUnauthenticatedRequestParameters: true
2929
};
3030

31-
const request_jwt: SqlParameterFunction = {
31+
export const request_jwt: SqlParameterFunction = {
3232
debugName: 'request.jwt',
3333
call(parameters: ParameterValueSet) {
3434
return parameters.rawTokenPayload;
@@ -42,7 +42,7 @@ const request_jwt: SqlParameterFunction = {
4242
usesUnauthenticatedRequestParameters: false
4343
};
4444

45-
const request_user_id: SqlParameterFunction = {
45+
export const request_user_id: SqlParameterFunction = {
4646
debugName: 'request.user_id',
4747
call(parameters: ParameterValueSet) {
4848
return parameters.userId;
@@ -61,20 +61,3 @@ export const REQUEST_FUNCTIONS: Record<string, SqlParameterFunction> = {
6161
jwt: request_jwt,
6262
user_id: request_user_id
6363
};
64-
65-
export const QUERY_FUNCTIONS: Record<string, SqlParameterFunction> = {
66-
params: {
67-
debugName: 'stream.params',
68-
call(parameters: ParameterValueSet) {
69-
return parameters.rawUserParameters;
70-
},
71-
getReturnType() {
72-
return ExpressionType.TEXT;
73-
},
74-
detail: 'Unauthenticated stream parameters as JSON',
75-
documentation:
76-
'Returns stream passed by the client when opening the stream. These parameters are not authenticated - any value can be passed in by the client.',
77-
usesAuthenticatedRequestParameters: false,
78-
usesUnauthenticatedRequestParameters: true
79-
}
80-
};

0 commit comments

Comments
 (0)