#[macro_use]
mod macros;
pub mod operation;
pub(crate) mod row;
pub mod statements;
mod table_source;
pub mod types;
#[cfg(feature = "vista")]
pub mod vista;
use sqlx::Connection as _;
use sqlx::mysql::{MySqlConnection, MySqlPool, MySqlPoolOptions};
pub use types::{AnyMysqlType, MysqlType};
crate::define_typed_ident!(
MysqlIdent,
mysql_ident,
AnyMysqlType,
crate::condition::MysqlCondition
);
#[derive(Clone)]
pub struct MysqlDB {
pool: MySqlPool,
}
impl MysqlDB {
pub async fn connect(url: &str) -> Result<Self, sqlx::Error> {
MySqlConnection::connect(url).await?.close().await?;
let pool = MySqlPoolOptions::new().connect_lazy(url)?;
Ok(Self { pool })
}
pub fn pool(&self) -> &MySqlPool {
&self.pool
}
pub async fn aggregate(
&self,
select: &statements::MysqlSelect,
func: &str,
column: impl vantage_expressions::Expressive<AnyMysqlType>,
) -> vantage_core::Result<AnyMysqlType> {
use vantage_expressions::ExprDataSource;
let expr = select.as_aggregate(func, column);
let result = self.execute(&expr).await?;
Ok(crate::sql_exec::first_cell::<Self>(result))
}
}
impl vantage_expressions::traits::datasource::DataSource for MysqlDB {}
mod expr_data_source;
mod selectable_data_source;