Derive Macro Database
#[derive(Database)]
{
// Attributes available to this derive:
#[database]
}
Expand description
Automatic derive for the Database trait.
use rocket_db_pools::Database;
#[derive(Database)]
#[database("database_name")]
struct Db(PoolType);The derive generates an implementation of Database as follows:
-
Database::NAMEis set to the value in the#[database("name")]attribute.This names the database, providing an anchor to configure the database via
Rocket.tomlor any other configuration source. Specifically, the configuration indatabases.nameis used to configure the driver. -
Database::Poolis set to the wrapped type:PoolTypeabove. The type must implementPool.
To meet the required Database supertrait bounds, this derive also
generates implementations for:
-
From<Db::Pool> -
Deref<Target = Db::Pool> -
DerefMut<Target = Db::Pool> -
FromRequest<'_> for &Db -
Sentinel for &Db
The Deref impls enable accessing the database pool directly from
references &Db or &mut Db. To force a dereference to the underlying
type, use &db.0 or &**db or their &mut variants.