pub trait AppDatabaseExt: Sized {
// Required methods
fn database<DB: Database>(
self,
url: &str,
) -> impl Future<Output = Result<Self, FletchError>> + Send;
fn database_with<DB: Database>(
self,
url: &str,
builder: PoolBuilder<DB>,
) -> impl Future<Output = Result<Self, FletchError>> + Send;
fn health_check_db<DB: Database>(self) -> Self;
fn migrate<DB>(
self,
path: &str,
) -> impl Future<Output = Result<Self, MigrateError>> + Send
where DB: Database,
<DB as Database>::Connection: Migrate;
}Expand description
Extension trait that adds database connection and migration methods to App.
Required Methods§
Sourcefn database<DB: Database>(
self,
url: &str,
) -> impl Future<Output = Result<Self, FletchError>> + Send
fn database<DB: Database>( self, url: &str, ) -> impl Future<Output = Result<Self, FletchError>> + Send
Connect to a database using the given URL and register the pool.
The fletch_orm::Pool<DB> is registered as a dependency and can be
extracted in actions via Dep<fletch_orm::Pool<DB>>.
Sourcefn database_with<DB: Database>(
self,
url: &str,
builder: PoolBuilder<DB>,
) -> impl Future<Output = Result<Self, FletchError>> + Send
fn database_with<DB: Database>( self, url: &str, builder: PoolBuilder<DB>, ) -> impl Future<Output = Result<Self, FletchError>> + Send
Connect to a database using the given URL and a pre-configured
fletch_orm::PoolBuilder, then register the pool.
This allows customizing pool settings such as max connections, idle timeout, and acquire timeout.
Sourcefn health_check_db<DB: Database>(self) -> Self
fn health_check_db<DB: Database>(self) -> Self
Register a GET /health/db route that checks database connectivity.
Returns 200 with pool stats when healthy, or 503 when unreachable.
Sourcefn migrate<DB>(
self,
path: &str,
) -> impl Future<Output = Result<Self, MigrateError>> + Send
fn migrate<DB>( self, path: &str, ) -> impl Future<Output = Result<Self, MigrateError>> + Send
Run SQLx migrations from the given directory path.
This registers a startup hook that runs all pending migrations
when the app starts (via serve() or
build_with_hooks()).
The path should point to a directory containing .sql migration files
following SQLx naming conventions (e.g. 20230101000000_create_users.sql).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".