pub struct DB;Expand description
Database facade - main entry point for database operations
Provides static methods for initializing and accessing the database connection. The connection is stored in the application container as a singleton.
§Example
ⓘ
use kit::{DB, DatabaseConfig, Config};
// Initialize (usually in bootstrap.rs)
Config::register(DatabaseConfig::from_env());
DB::init().await?;
// Use anywhere in your app
let conn = DB::connection()?;Implementations§
Source§impl DB
impl DB
Sourcepub async fn init() -> Result<(), FrameworkError>
pub async fn init() -> Result<(), FrameworkError>
Initialize the database connection
Reads configuration from DatabaseConfig (must be registered via Config system)
and establishes a connection pool. The connection is stored in the App container.
§Errors
Returns an error if:
DatabaseConfigis not registered- Connection to the database fails
§Example
ⓘ
// In bootstrap.rs
pub async fn register() {
DB::init().await.expect("Failed to connect to database");
}Sourcepub async fn init_with(config: DatabaseConfig) -> Result<(), FrameworkError>
pub async fn init_with(config: DatabaseConfig) -> Result<(), FrameworkError>
Sourcepub fn connection() -> Result<DbConnection, FrameworkError>
pub fn connection() -> Result<DbConnection, FrameworkError>
Get the database connection
Returns the connection from the App container. The connection is wrapped
in a DbConnection which provides convenient access to the underlying
SeaORM DatabaseConnection.
§Errors
Returns an error if DB::init() was not called.
§Example
ⓘ
let conn = DB::connection()?;
// Use with SeaORM queries
let users = User::find()
.all(conn.inner())
.await?;Sourcepub fn is_connected() -> bool
pub fn is_connected() -> bool
Auto Trait Implementations§
impl Freeze for DB
impl RefUnwindSafe for DB
impl Send for DB
impl Sync for DB
impl Unpin for DB
impl UnwindSafe for DB
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> 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