use crate::{Dialect, Result, Row, ShardRoute};
use sea_query::Value;
#[derive(Debug, Clone, Copy, Default)]
pub struct ExecOutcome {
pub rows_affected: u64,
pub last_insert_id: i64,
}
#[allow(async_fn_in_trait)]
pub trait Executor {
fn dialect(&self) -> Dialect;
fn shard_family(&self) -> Option<&str> {
None
}
fn is_sharded(&self) -> bool {
self.shard_family().is_some()
}
fn allocate_id(&self, _shard_key: u64) -> Option<u64> {
None
}
async fn fetch_all(&self, sql: &str, params: Vec<Value>) -> Result<Vec<Box<dyn Row>>>;
async fn execute(&self, sql: &str, params: Vec<Value>) -> Result<ExecOutcome>;
async fn fetch_all_routed(
&self,
_route: ShardRoute,
sql: &str,
params: Vec<Value>,
) -> Result<Vec<Box<dyn Row>>> {
self.fetch_all(sql, params).await
}
async fn execute_routed(
&self,
_route: ShardRoute,
sql: &str,
params: Vec<Value>,
) -> Result<ExecOutcome> {
self.execute(sql, params).await
}
}