Skip to content

Commit c48bff1

Browse files
pass null as row consumer results in array of values being returned by query
1 parent 8a111b9 commit c48bff1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ simple-logging = "2.0.2"
6363
backtrace = "0.3.56"
6464
url = "2.2.1"
6565
gpp = "0.6"
66+
either = "1"
6667

6768
reqwest = { version = "0.12", features = ["rustls-tls", "cookies", "gzip", "deflate", "multipart", "blocking"], optional = true, default-features = false }
6869
gpio-cdev = { git = "https://github.com/rust-embedded/gpio-cdev", optional = true, features = ["async-tokio", "futures"] }

src/modules/db/sqlx/mod.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,13 @@ async fn exe_query_mysql<'e>(
304304
}
305305
}
306306

307-
if let JsValueFacade::JsFunction { cached_function } = row_consumer {
307+
if row_consumer.is_null_or_undefined() {
308+
// turn row args vec into array
309+
let arr_facade = JsValueFacade::Array {
310+
val: row_args_vec
311+
};
312+
ret_vec.push(arr_facade);
313+
} else if let JsValueFacade::JsFunction { cached_function } = row_consumer {
308314
let mut func_res = cached_function.invoke_function(row_args_vec).await?;
309315
while let JsValueFacade::JsPromise { cached_promise } = func_res {
310316
let prom_res = cached_promise.get_promise_result().await?;
@@ -566,7 +572,13 @@ async fn exe_query_postgres<'e>(
566572
}
567573
}
568574

569-
if let JsValueFacade::JsFunction { cached_function } = row_consumer {
575+
if row_consumer.is_null_or_undefined() {
576+
// turn row args vec into array
577+
let arr_facade = JsValueFacade::Array {
578+
val: row_args_vec
579+
};
580+
ret_vec.push(arr_facade);
581+
} else if let JsValueFacade::JsFunction { cached_function } = row_consumer {
570582
let mut func_res = cached_function.invoke_function(row_args_vec).await?;
571583
while let JsValueFacade::JsPromise { cached_promise } = func_res {
572584
let prom_res = cached_promise.get_promise_result().await?;
@@ -1079,9 +1091,9 @@ unsafe extern "C" fn fn_connection_query(
10791091
if !(args.len() == 3
10801092
&& args[0].is_string()
10811093
&& (args[1].is_array() || args[1].is_object() || args[1].is_null())
1082-
&& args[2].is_function())
1094+
&& (args[2].is_function() || args[2].is_null()))
10831095
{
1084-
return q_ctx.report_ex("query requires three args (qry: string, arguments: Array<primitive> | Record<string, primitive>, row_consumer: () => Promise<any>)");
1096+
return q_ctx.report_ex("query requires three args (qry: string, arguments: null | Array<primitive> | Record<string, primitive>, row_consumer: null | () => Promise<any>)");
10851097
}
10861098

10871099
if let Some(proxy_instance_id) = get_proxy_instance_id(context, &this_val_adapter) {
@@ -1364,9 +1376,9 @@ unsafe extern "C" fn fn_transaction_query(
13641376
if !(args.len() == 3
13651377
&& args[0].is_string()
13661378
&& (args[1].is_array() || args[1].is_object() || args[1].is_null())
1367-
&& args[2].is_function())
1379+
&& (args[2].is_function() || args[2].is_null()))
13681380
{
1369-
return q_ctx.report_ex("query requires three args (qry: string, arguments: Array<primitive> | Record<string, primitive>, row_consumer: () => Promise<any>)");
1381+
return q_ctx.report_ex("query requires three args (qry: string, arguments: null | Array<primitive> | Record<string, primitive>, row_consumer: null | () => Promise<any>)");
13701382
}
13711383

13721384
if let Some(proxy_instance_id) = get_proxy_instance_id(context, &this_val_adapter) {

0 commit comments

Comments
 (0)