Separate out synchronous and asynchronous SQL functions

This commit is contained in:
Tobie Morgan Hitchcock 2022-08-16 22:07:53 +01:00
parent 038246f054
commit 2945b7d724

View file

@ -22,7 +22,22 @@ pub mod time;
pub mod r#type; pub mod r#type;
pub mod util; pub mod util;
// Attempts to run any function
pub async fn run(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Value, Error> { pub async fn run(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Value, Error> {
match name {
v if v.starts_with("http") => {
// HTTP functions are asynchronous
asynchronous(ctx, name, args).await
}
_ => {
// Other functions are synchronous
synchronous(ctx, name, args)
}
}
}
// Attempts to run a synchronous function
pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Value, Error> {
match name { match name {
// //
"array::combine" => args::check(ctx, name, args, Args::Two, array::combine), "array::combine" => args::check(ctx, name, args, Args::Two, array::combine),
@ -56,13 +71,6 @@ pub async fn run(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Valu
"geo::hash::decode" => args::check(ctx, name, args, Args::One, geo::hash::decode), "geo::hash::decode" => args::check(ctx, name, args, Args::One, geo::hash::decode),
"geo::hash::encode" => args::check(ctx, name, args, Args::OneTwo, geo::hash::encode), "geo::hash::encode" => args::check(ctx, name, args, Args::OneTwo, geo::hash::encode),
// //
"http::head" => http::head(ctx, args).await,
"http::get" => http::get(ctx, args).await,
"http::put" => http::put(ctx, args).await,
"http::post" => http::post(ctx, args).await,
"http::patch" => http::patch(ctx, args).await,
"http::delete" => http::delete(ctx, args).await,
//
"is::alphanum" => args::check(ctx, name, args, Args::One, is::alphanum), "is::alphanum" => args::check(ctx, name, args, Args::One, is::alphanum),
"is::alpha" => args::check(ctx, name, args, Args::One, is::alpha), "is::alpha" => args::check(ctx, name, args, Args::One, is::alpha),
"is::ascii" => args::check(ctx, name, args, Args::One, is::ascii), "is::ascii" => args::check(ctx, name, args, Args::One, is::ascii),
@ -166,3 +174,18 @@ pub async fn run(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Valu
_ => unreachable!(), _ => unreachable!(),
} }
} }
// Attempts to run an asynchronous function
pub async fn asynchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Value, Error> {
match name {
//
"http::head" => http::head(ctx, args).await,
"http::get" => http::get(ctx, args).await,
"http::put" => http::put(ctx, args).await,
"http::post" => http::post(ctx, args).await,
"http::patch" => http::patch(ctx, args).await,
"http::delete" => http::delete(ctx, args).await,
//
_ => unreachable!(),
}
}