1#![cfg(any(feature = "postgres", feature = "sqlite"))]
2
3mod consts;
4pub mod qb;
5mod selectable;
6pub use consts::*;
7mod sb;
8
9pub use crate::qb::TableInfo;
10pub use async_trait::async_trait;
11pub use qb::Column;
12pub use qb::Condition;
13pub use qb::*;
14mod traits;
15
16#[cfg(any(feature = "postgres", feature = "sqlite"))]
17pub use driver::{Connection, Driver, Pool, Row};
18
19pub use sb::SB;
20use sqlx::FromRow;
21pub use traits::FromAliasedRow;
22pub use traits::GenericExecutor;
23pub use traits::StatementExecutor;
24pub use traits::Table;
25
26#[async_trait]
27impl<T> GenericExecutor<T> for QB<T>
28where
29 T: for<'r> FromRow<'r, Row> + Send + Unpin + std::fmt::Debug,
30{
31 async fn fetch_one_as(mut self, pool: &Pool) -> sqlx::Result<T> {
32 self.eager.clear();
33 self.batch.clear();
34 let row = self.build_query().build().fetch_one(pool).await?;
35 T::from_row(&row)
36 }
37
38 async fn fetch_all_as(self, pool: &Pool) -> sqlx::Result<Vec<T>> {
39 let rows = self.build_query().build().fetch_all(pool).await?;
40 rows.iter().map(T::from_row).collect()
41 }
42}
43
44pub mod driver {
45 #[cfg(all(feature = "postgres", feature = "sqlite"))]
46 compile_error!(
47 "only one database driver can be set – please enable either 'postgres' or 'sqlite' feature, not both"
48 );
49
50 #[cfg(feature = "postgres")]
51 pub type Driver = sqlx::Postgres;
53
54 #[cfg(feature = "postgres")]
55 pub type Pool = sqlx::PgPool;
57
58 #[cfg(feature = "postgres")]
59 pub type Connection = sqlx::PgConnection;
61
62 #[cfg(feature = "postgres")]
63 pub type Row = sqlx::postgres::PgRow;
65
66 #[cfg(feature = "sqlite")]
67 pub type Driver = sqlx::Sqlite;
69
70 #[cfg(feature = "sqlite")]
71 pub type Pool = sqlx::SqlitePool;
73
74 #[cfg(feature = "sqlite")]
75 pub type Connection = sqlx::SqliteConnection;
77
78 #[cfg(feature = "sqlite")]
79 pub type Row = sqlx::sqlite::SqliteRow;
81}
82
83#[doc(hidden)]
84pub use sqlx;