pub struct DbConnection { /* private fields */ }Expand description
Wrapper around SeaORM’s DatabaseConnection
This provides a clonable, thread-safe connection that can be stored in the application container and shared across requests.
§Example
ⓘ
let conn = DbConnection::connect(&config).await?;
// Use with SeaORM queries
let users = User::find().all(conn.inner()).await?;Implementations§
Source§impl DbConnection
impl DbConnection
Sourcepub async fn connect(config: &DatabaseConfig) -> Result<Self, FrameworkError>
pub async fn connect(config: &DatabaseConfig) -> Result<Self, FrameworkError>
Create a new database connection from config
This establishes a connection pool using the provided configuration. For SQLite databases, this will automatically create the database file if it doesn’t exist.
Sourcepub fn inner(&self) -> &DatabaseConnection
pub fn inner(&self) -> &DatabaseConnection
Sourcepub fn conn(&self) -> &DatabaseConnection
pub fn conn(&self) -> &DatabaseConnection
Methods from Deref<Target = DatabaseConnection>§
Sourcepub async fn ping(&self) -> Result<(), DbErr>
pub async fn ping(&self) -> Result<(), DbErr>
Checks if a connection to the database is still valid.
Sourcepub async fn close_by_ref(&self) -> Result<(), DbErr>
pub async fn close_by_ref(&self) -> Result<(), DbErr>
Explicitly close the database connection
Sourcepub fn get_postgres_connection_pool(&self) -> &Pool<Postgres>
pub fn get_postgres_connection_pool(&self) -> &Pool<Postgres>
Sourcepub fn get_sqlite_connection_pool(&self) -> &Pool<Sqlite>
pub fn get_sqlite_connection_pool(&self) -> &Pool<Sqlite>
Trait Implementations§
Source§impl AsRef<DatabaseConnection> for DbConnection
impl AsRef<DatabaseConnection> for DbConnection
Source§fn as_ref(&self) -> &DatabaseConnection
fn as_ref(&self) -> &DatabaseConnection
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl Clone for DbConnection
impl Clone for DbConnection
Source§fn clone(&self) -> DbConnection
fn clone(&self) -> DbConnection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DbConnection
impl !RefUnwindSafe for DbConnection
impl Send for DbConnection
impl Sync for DbConnection
impl Unpin for DbConnection
impl UnsafeUnpin for DbConnection
impl !UnwindSafe for DbConnection
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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