Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/db_pools/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sqlx_macros = ["sqlx/macros"]
# diesel features
diesel_postgres = ["diesel-async/postgres", "diesel-async/deadpool", "deadpool", "diesel"]
diesel_mysql = ["diesel-async/mysql", "diesel-async/deadpool", "deadpool", "diesel"]
diesel_sqlite = ["diesel-async/sqlite", "diesel-async/deadpool", "deadpool", "diesel"]
# implicit features: mongodb

[dependencies.rocket]
Expand Down
26 changes: 26 additions & 0 deletions contrib/db_pools/lib/src/diesel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ pub use diesel_async::AsyncMysqlConnection;
#[cfg(feature = "diesel_postgres")]
pub use diesel_async::AsyncPgConnection;

#[doc(inline)]
#[cfg(feature = "diesel_sqlite")]
pub use diesel_async::sync_connection_wrapper::SyncConnectionWrapper;

/// Alias of a `Result` with an error type of [`Debug`] for a `diesel::Error`.
///
/// `QueryResult` is a [`Responder`](rocket::response::Responder) when `T` (the
Expand Down Expand Up @@ -150,3 +154,25 @@ pub type MysqlPool = Pool<AsyncMysqlConnection>;
/// ```
#[cfg(feature = "diesel_postgres")]
pub type PgPool = Pool<AsyncPgConnection>;

/// Type alias for an `async` pool of Sqlite connections for `async` [diesel].
///
/// ```rust
/// # extern crate rocket;
/// # #[cfg(feature = "diesel_sqlite")] {
/// # use rocket::get;
/// use rocket_db_pools::{Database, Connection};
/// use rocket_db_pools::diesel::{SqlitePool, prelude::*};
///
/// #[derive(Database)]
/// #[database("my_sqlite_db_name")]
/// struct Db(SqlitePool);
///
/// #[get("/")]
/// async fn use_db(mut db: Connection<Db>) {
/// /* .. */
/// }
/// # }
/// ```
#[cfg(feature = "diesel_sqlite")]
pub type SqlitePool = Pool<SyncConnectionWrapper<SqliteConnection>>;
15 changes: 10 additions & 5 deletions contrib/db_pools/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@
//!
//! ## `diesel` (v2)
//!
//! | Database | Feature | [`Pool`] Type | [`Connection`] Deref |
//! |----------|-------------------|-----------------------|----------------------------------|
//! | Postgres | `diesel_postgres` | [`diesel::PgPool`] | [`diesel::AsyncPgConnection`] |
//! | MySQL | `diesel_mysql` | [`diesel::MysqlPool`] | [`diesel::AsyncMysqlConnection`] | //!
//! | Database | Feature | [`Pool`] Type | [`Connection`] Deref |
//! |----------|-------------------|------------------------|--------------------------------------------------------------|
//! | Postgres | `diesel_postgres` | [`diesel::PgPool`] | [`diesel::AsyncPgConnection`] |
//! | MySQL | `diesel_mysql` | [`diesel::MysqlPool`] | [`diesel::AsyncMysqlConnection`] |
//! | SQLite | `diesel_sqlite` | [`diesel::SqlitePool`] | [`diesel::SyncConnectionWrapper<diesel::SqliteConnection>>`] |
//!
//! See [`diesel`] for usage details.
//!
Expand Down Expand Up @@ -243,7 +244,11 @@ pub use rocket;
#[doc(inline)]
pub use rocket::figment;

#[cfg(any(feature = "diesel_postgres", feature = "diesel_mysql"))] pub mod diesel;
#[cfg(any(
feature = "diesel_postgres",
feature = "diesel_mysql",
feature = "diesel_sqlite"
))] pub mod diesel;
#[cfg(feature = "deadpool_postgres")] pub use deadpool_postgres;
#[cfg(feature = "deadpool_redis")] pub use deadpool_redis;
#[cfg(feature = "mongodb")] pub use mongodb;
Expand Down
9 changes: 9 additions & 0 deletions contrib/db_pools/lib/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ mod deadpool_postgres {
}
}

#[cfg(feature = "diesel_sqlite")]
impl DeadManager for AsyncDieselConnectionManager<
diesel_async::sync_connection_wrapper::SyncConnectionWrapper::<diesel::SqliteConnection>
> {
fn new(config: &Config) -> Result<Self, Self::Error> {
Ok(Self::new(config.url.as_str()))
}
}

#[rocket::async_trait]
impl<M: DeadManager, C: From<Object<M>>> crate::Pool for Pool<M, C>
where M::Type: Send, C: Send + Sync + 'static, M::Error: std::error::Error
Expand Down