Skip to content

Commit 18435a4

Browse files
committed
Update table-valued functions test as well
1 parent c127ad2 commit 18435a4

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

.changeset/olive-games-destroy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@powersync/service-sync-rules': minor
3+
'@powersync/service-image': minor
4+
---
5+
6+
Add the `legacy_json_extract` quirk. When marked as fixed, JSON-extracting operators are updated to match SQLite more closely.

packages/sync-rules/test/src/table_valued_function_queries.test.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { describe, expect, test } from 'vitest';
2-
import { RequestParameters, SqlParameterQuery } from '../../src/index.js';
2+
import {
3+
CompatibilityContext,
4+
CompatibilityEdition,
5+
CompatibilityOption,
6+
RequestParameters,
7+
SqlParameterQuery
8+
} from '../../src/index.js';
39
import { StaticSqlParameterQuery } from '../../src/StaticSqlParameterQuery.js';
410
import { identityBucketTransformer, PARSE_OPTIONS } from './util.js';
511

@@ -20,13 +26,45 @@ describe('table-valued function queries', () => {
2026

2127
expect(
2228
query.getStaticBucketDescriptions(
23-
new RequestParameters({ sub: '' }, { array: [1, 2, 3] }),
29+
new RequestParameters({ sub: '' }, { array: [1, 2, 3, null] }),
2430
identityBucketTransformer
2531
)
2632
).toEqual([
2733
{ bucket: 'mybucket[1]', priority: 3 },
2834
{ bucket: 'mybucket[2]', priority: 3 },
29-
{ bucket: 'mybucket[3]', priority: 3 }
35+
{ bucket: 'mybucket[3]', priority: 3 },
36+
{ bucket: 'mybucket["null"]', priority: 3 }
37+
]);
38+
});
39+
40+
test('json_each(array param), fixed json', function () {
41+
const sql = "SELECT json_each.value as v FROM json_each(request.parameters() -> 'array')";
42+
const query = SqlParameterQuery.fromSql(
43+
'mybucket',
44+
sql,
45+
{
46+
...PARSE_OPTIONS,
47+
accept_potentially_dangerous_queries: true,
48+
compatibility: new CompatibilityContext(
49+
CompatibilityEdition.LEGACY,
50+
new Map([[CompatibilityOption.fixedJsonExtract, true]])
51+
)
52+
},
53+
'1'
54+
) as StaticSqlParameterQuery;
55+
expect(query.errors).toEqual([]);
56+
expect(query.bucketParameters).toEqual(['v']);
57+
58+
expect(
59+
query.getStaticBucketDescriptions(
60+
new RequestParameters({ sub: '' }, { array: [1, 2, 3, null] }),
61+
identityBucketTransformer
62+
)
63+
).toEqual([
64+
{ bucket: 'mybucket[1]', priority: 3 },
65+
{ bucket: 'mybucket[2]', priority: 3 },
66+
{ bucket: 'mybucket[3]', priority: 3 },
67+
{ bucket: 'mybucket[null]', priority: 3 }
3068
]);
3169
});
3270

0 commit comments

Comments
 (0)