use std::future::Future;
use std::pin::Pin;
use crate::job::Job;
use crate::pool::{Pool, Reserved};
use crate::query::Rows;
pub trait Executor {
fn execute<'a>(
&'a self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>>;
fn execute_with<'a>(
&'a self,
sql: &'a str,
params: &'a [serde_json::Value],
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>>;
}
impl Executor for Job {
fn execute<'a>(
&'a self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>> {
Box::pin(async move { Job::execute(self, sql).await })
}
fn execute_with<'a>(
&'a self,
sql: &'a str,
params: &'a [serde_json::Value],
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>> {
Box::pin(async move { Job::execute_with(self, sql, params).await })
}
}
impl Executor for Pool {
fn execute<'a>(
&'a self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>> {
Box::pin(Pool::execute(self, sql))
}
fn execute_with<'a>(
&'a self,
sql: &'a str,
params: &'a [serde_json::Value],
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>> {
Box::pin(Pool::execute_with(self, sql, params))
}
}
impl Executor for Reserved {
fn execute<'a>(
&'a self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>> {
let job: &Job = self;
Box::pin(async move { Job::execute(job, sql).await })
}
fn execute_with<'a>(
&'a self,
sql: &'a str,
params: &'a [serde_json::Value],
) -> Pin<Box<dyn Future<Output = crate::Result<Rows>> + Send + 'a>> {
let job: &Job = self;
Box::pin(async move { Job::execute_with(job, sql, params).await })
}
}