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