Skip to content

Commit 4206ed9

Browse files
committed
move documentation of SyncConnectionWrapper to where it is made public
1 parent 48a41a1 commit 4206ed9

File tree

1 file changed

+47
-38
lines changed
  • src/sync_connection_wrapper

1 file changed

+47
-38
lines changed

src/sync_connection_wrapper/mod.rs

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,56 @@ pub trait SpawnBlocking {
3232
fn get_runtime() -> Self;
3333
}
3434

35+
/// A wrapper of a [`diesel::connection::Connection`] usable in async context.
36+
///
37+
/// It implements AsyncConnection if [`diesel::connection::Connection`] fullfils requirements:
38+
/// * it's a [`diesel::connection::LoadConnection`]
39+
/// * its [`diesel::connection::Connection::Backend`] has a [`diesel::query_builder::BindCollector`] implementing [`diesel::query_builder::MoveableBindCollector`]
40+
/// * its [`diesel::connection::LoadConnection::Row`] implements [`diesel::row::IntoOwnedRow`]
41+
///
42+
/// Internally this wrapper type will use `spawn_blocking` on tokio
43+
/// to execute the request on the inner connection. This implies a
44+
/// dependency on tokio and that the runtime is running.
45+
///
46+
/// Note that only SQLite is supported at the moment.
47+
///
48+
/// # Examples
49+
///
50+
/// ```rust
51+
/// # include!("../doctest_setup.rs");
52+
/// use diesel_async::RunQueryDsl;
53+
/// use schema::users;
54+
///
55+
/// async fn some_async_fn() {
56+
/// # let database_url = database_url();
57+
/// use diesel_async::AsyncConnection;
58+
/// use diesel::sqlite::SqliteConnection;
59+
/// let mut conn =
60+
/// SyncConnectionWrapper::<SqliteConnection>::establish(&database_url).await.unwrap();
61+
/// # create_tables(&mut conn).await;
62+
///
63+
/// let all_users = users::table.load::<(i32, String)>(&mut conn).await.unwrap();
64+
/// # assert_eq!(all_users.len(), 2);
65+
/// }
66+
///
67+
/// # #[cfg(feature = "sqlite")]
68+
/// # #[tokio::main]
69+
/// # async fn main() {
70+
/// # some_async_fn().await;
71+
/// # }
72+
/// ```
3573
#[cfg(feature = "tokio")]
3674
pub type SyncConnectionWrapper<C, B = self::implementation::Tokio> = self::implementation::SyncConnectionWrapper<C, B>;
3775

76+
/// A wrapper of a [`diesel::connection::Connection`] usable in async context.
77+
///
78+
/// It implements AsyncConnection if [`diesel::connection::Connection`] fullfils requirements:
79+
/// * it's a [`diesel::connection::LoadConnection`]
80+
/// * its [`diesel::connection::Connection::Backend`] has a [`diesel::query_builder::BindCollector`] implementing [`diesel::query_builder::MoveableBindCollector`]
81+
/// * its [`diesel::connection::LoadConnection::Row`] implements [`diesel::row::IntoOwnedRow`]
82+
///
83+
/// Internally this wrapper type will use `spawn_blocking` on given type implementing [`SpawnBlocking`] trait
84+
/// to execute the request on the inner connection.
3885
#[cfg(not(feature = "tokio"))]
3986
pub use self::implementation::SyncConnectionWrapper;
4087

@@ -66,44 +113,6 @@ mod implementation {
66113
)
67114
}
68115

69-
/// A wrapper of a [`diesel::connection::Connection`] usable in async context.
70-
///
71-
/// It implements AsyncConnection if [`diesel::connection::Connection`] fullfils requirements:
72-
/// * it's a [`diesel::connection::LoadConnection`]
73-
/// * its [`diesel::connection::Connection::Backend`] has a [`diesel::query_builder::BindCollector`] implementing [`diesel::query_builder::MoveableBindCollector`]
74-
/// * its [`diesel::connection::LoadConnection::Row`] implements [`diesel::row::IntoOwnedRow`]
75-
///
76-
/// Internally this wrapper type will use `spawn_blocking` on tokio
77-
/// to execute the request on the inner connection. This implies a
78-
/// dependency on tokio and that the runtime is running.
79-
///
80-
/// Note that only SQLite is supported at the moment.
81-
///
82-
/// # Examples
83-
///
84-
/// ```rust
85-
/// # include!("../doctest_setup.rs");
86-
/// use diesel_async::RunQueryDsl;
87-
/// use schema::users;
88-
///
89-
/// async fn some_async_fn() {
90-
/// # let database_url = database_url();
91-
/// use diesel_async::AsyncConnection;
92-
/// use diesel::sqlite::SqliteConnection;
93-
/// let mut conn =
94-
/// SyncConnectionWrapper::<SqliteConnection>::establish(&database_url).await.unwrap();
95-
/// # create_tables(&mut conn).await;
96-
///
97-
/// let all_users = users::table.load::<(i32, String)>(&mut conn).await.unwrap();
98-
/// # assert_eq!(all_users.len(), 2);
99-
/// }
100-
///
101-
/// # #[cfg(feature = "sqlite")]
102-
/// # #[tokio::main]
103-
/// # async fn main() {
104-
/// # some_async_fn().await;
105-
/// # }
106-
/// ```
107116
pub struct SyncConnectionWrapper<C, S> {
108117
inner: Arc<Mutex<C>>,
109118
runtime: S,

0 commit comments

Comments
 (0)