@@ -39,6 +39,7 @@ pub(crate) enum StmtParam {
3939 Null ,
4040 Concat ( Vec < StmtParam > ) ,
4141 JsonObject ( Vec < StmtParam > ) ,
42+ JsonArray ( Vec < StmtParam > ) ,
4243 FunctionCall ( SqlPageFunctionCall ) ,
4344}
4445
@@ -64,6 +65,13 @@ impl std::fmt::Display for StmtParam {
6465 }
6566 write ! ( f, ")" )
6667 }
68+ StmtParam :: JsonArray ( items) => {
69+ write ! ( f, "JSON_ARRAY(" ) ?;
70+ for item in items {
71+ write ! ( f, "{item}, " ) ?;
72+ }
73+ write ! ( f, ")" )
74+ }
6775 StmtParam :: FunctionCall ( call) => write ! ( f, "{call}" ) ,
6876 StmtParam :: Error ( x) => {
6977 if let Some ( ( i, _) ) = x. char_indices ( ) . nth ( 21 ) {
@@ -154,6 +162,7 @@ pub(super) async fn extract_req_param<'a, 'b>(
154162 StmtParam :: Null => None ,
155163 StmtParam :: Concat ( args) => concat_params ( & args[ ..] , request, db_connection) . await ?,
156164 StmtParam :: JsonObject ( args) => json_object_params ( & args[ ..] , request, db_connection) . await ?,
165+ StmtParam :: JsonArray ( args) => json_array_params ( & args[ ..] , request, db_connection) . await ?,
157166 StmtParam :: FunctionCall ( func) => func. evaluate ( request, db_connection) . await . with_context ( || {
158167 format ! (
159168 "Error in function call {func}.\n Expected {:#}" ,
@@ -200,3 +209,20 @@ async fn json_object_params<'a, 'b>(
200209 map_ser. end ( ) ?;
201210 Ok ( Some ( Cow :: Owned ( String :: from_utf8 ( result) ?) ) )
202211}
212+
213+ async fn json_array_params < ' a , ' b > (
214+ args : & [ StmtParam ] ,
215+ request : & ' a RequestInfo ,
216+ db_connection : & ' b mut DbConn ,
217+ ) -> anyhow:: Result < Option < Cow < ' a , str > > > {
218+ use serde:: { ser:: SerializeSeq , Serializer } ;
219+ let mut result = Vec :: new ( ) ;
220+ let mut ser = serde_json:: Serializer :: new ( & mut result) ;
221+ let mut seq_ser = ser. serialize_seq ( Some ( args. len ( ) ) ) ?;
222+ for element in args {
223+ let element = Box :: pin ( extract_req_param ( element, request, db_connection) ) . await ?;
224+ seq_ser. serialize_element ( & element) ?;
225+ }
226+ seq_ser. end ( ) ?;
227+ Ok ( Some ( Cow :: Owned ( String :: from_utf8 ( result) ?) ) )
228+ }
0 commit comments