Skip to content

Commit d57b35d

Browse files
committed
Update table-valued functions test as well
1 parent 2c79822 commit d57b35d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-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: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from 'vitest';
2-
import { RequestParameters, SqlParameterQuery } from '../../src/index.js';
2+
import { Quirk, RequestParameters, SqlParameterQuery } from '../../src/index.js';
33
import { StaticSqlParameterQuery } from '../../src/StaticSqlParameterQuery.js';
44
import { PARSE_OPTIONS } from './util.js';
55

@@ -18,10 +18,34 @@ describe('table-valued function queries', () => {
1818
expect(query.errors).toEqual([]);
1919
expect(query.bucketParameters).toEqual(['v']);
2020

21-
expect(query.getStaticBucketDescriptions(new RequestParameters({ sub: '' }, { array: [1, 2, 3] }))).toEqual([
21+
expect(query.getStaticBucketDescriptions(new RequestParameters({ sub: '' }, { array: [1, 2, 3, null] }))).toEqual([
2222
{ bucket: 'mybucket[1]', priority: 3 },
2323
{ bucket: 'mybucket[2]', priority: 3 },
24-
{ bucket: 'mybucket[3]', priority: 3 }
24+
{ bucket: 'mybucket[3]', priority: 3 },
25+
{ bucket: 'mybucket["null"]', priority: 3 }
26+
]);
27+
});
28+
29+
test('json_each(array param), fixed json', function () {
30+
const sql = "SELECT json_each.value as v FROM json_each(request.parameters() -> 'array')";
31+
const query = SqlParameterQuery.fromSql(
32+
'mybucket',
33+
sql,
34+
{
35+
...PARSE_OPTIONS,
36+
accept_potentially_dangerous_queries: true,
37+
fixedQuirks: [Quirk.legacyJsonExtract]
38+
},
39+
'1'
40+
) as StaticSqlParameterQuery;
41+
expect(query.errors).toEqual([]);
42+
expect(query.bucketParameters).toEqual(['v']);
43+
44+
expect(query.getStaticBucketDescriptions(new RequestParameters({ sub: '' }, { array: [1, 2, 3, null] }))).toEqual([
45+
{ bucket: 'mybucket[1]', priority: 3 },
46+
{ bucket: 'mybucket[2]', priority: 3 },
47+
{ bucket: 'mybucket[3]', priority: 3 },
48+
{ bucket: 'mybucket[null]', priority: 3 }
2549
]);
2650
});
2751

0 commit comments

Comments
 (0)