pub struct Database { /* private fields */ }Expand description
The connection pool for one database. Clone-free: share it behind an Arc or in Rocket’s state.
The driver comes from the URL’s scheme: mysql:// (or mariadb://), postgres:// (or
postgresql://) and sqlite:. A scheme whose feature is not enabled is an error.
Implementations§
Source§impl Database
impl Database
Sourcepub async fn connect(url: &str) -> Result<Self, Error>
pub async fn connect(url: &str) -> Result<Self, Error>
Connects to the database at url, such as mysql://user:password@host/database,
postgres://user:password@host/database or sqlite:path/to/file.db.
Sourcepub async fn connect_with(
url: &str,
options: PoolOptions,
) -> Result<Self, Error>
pub async fn connect_with( url: &str, options: PoolOptions, ) -> Result<Self, Error>
Connects to the database at url with the pool settings in options. connect uses
PoolOptions::default().
Sourcepub fn pool(&self) -> &MySqlPool
pub fn pool(&self) -> &MySqlPool
The MySQL pool, for queries that Orbit does not wrap yet.
§Panics
Panics when the database is not MySQL. Check driver() first, or use postgres_pool or
sqlite_pool.
Sourcepub async fn transaction<T, E, F>(&self, f: F) -> Result<T, E>
pub async fn transaction<T, E, F>(&self, f: F) -> Result<T, E>
Runs f in a transaction and returns what it returns. The transaction commits when f
returns Ok and rolls back when it returns Err. A panic in f rolls it back too, since
nothing commits before f returns. Queries that must run inside the transaction take it
as &mut *tx.
The closure is an async closure: db.transaction(async |tx| { ... Ok(value) }).await.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Database
impl !UnwindSafe for Database
impl Forget for Database
impl Freeze for Database
impl Move for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more