1
1
import { describe , expect , test } from 'vitest' ;
2
- import { RequestParameters , SqlParameterQuery } from '../../src/index.js' ;
2
+ import { Quirk , RequestParameters , SqlParameterQuery } from '../../src/index.js' ;
3
3
import { StaticSqlParameterQuery } from '../../src/StaticSqlParameterQuery.js' ;
4
4
import { PARSE_OPTIONS } from './util.js' ;
5
5
@@ -18,10 +18,34 @@ describe('table-valued function queries', () => {
18
18
expect ( query . errors ) . toEqual ( [ ] ) ;
19
19
expect ( query . bucketParameters ) . toEqual ( [ 'v' ] ) ;
20
20
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 ( [
22
22
{ bucket : 'mybucket[1]' , priority : 3 } ,
23
23
{ 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 }
25
49
] ) ;
26
50
} ) ;
27
51
0 commit comments