Expand description
Database routing: pick the database alias for reads and writes
(Django DATABASE_ROUTERS).
Implement DatabaseRouter and attach it with
Databases::with_router. Each hook may
return an alias registered in the Databases; None
defers to the default ("default"). A router naming an alias that is not
registered yields OrmError::UnknownDatabase.
ⓘ
struct ReplicaRouter;
impl DatabaseRouter for ReplicaRouter {
fn db_for_read(&self, _model: &ModelMeta) -> Option<&str> {
Some("replica")
}
}Traits§
- Database
Router - Chooses the database alias for a model. Every hook has a neutral default.