11import { 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' ;
39import { StaticSqlParameterQuery } from '../../src/StaticSqlParameterQuery.js' ;
410import { 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