From 2945b7d724b660f9b32579675e8ee16b43c5a82f Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 16 Aug 2022 22:07:53 +0100 Subject: [PATCH] Separate out synchronous and asynchronous SQL functions --- lib/src/fnc/mod.rs | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index 669f7cc1..a79c56d5 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -22,7 +22,22 @@ pub mod time; pub mod r#type; pub mod util; +// Attempts to run any function pub async fn run(ctx: &Context<'_>, name: &str, args: Vec) -> Result { + 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) -> Result { match name { // "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) -> Result args::check(ctx, name, args, Args::One, geo::hash::decode), "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::alpha" => args::check(ctx, name, args, Args::One, is::alpha), "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) -> Result unreachable!(), } } + +// Attempts to run an asynchronous function +pub async fn asynchronous(ctx: &Context<'_>, name: &str, args: Vec) -> Result { + 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!(), + } +}