mirror of https://github.com/rwf2/Rocket.git
Flesh out database examples in the API documentation:
* Demonstrate multiple databases in ROCKET_DATABASES environment variable. * Add a second example of connection guard type creation.
This commit is contained in:
parent
ecc17d191f
commit
622f4f399c
|
@ -177,7 +177,14 @@
|
||||||
//! guide](https://rocket.rs/v0.4/guide/configuration/#environment-variables):
|
//! guide](https://rocket.rs/v0.4/guide/configuration/#environment-variables):
|
||||||
//!
|
//!
|
||||||
//! ```bash
|
//! ```bash
|
||||||
//! ROCKET_DATABASES={my_db={url="db.sqlite"}}
|
//! ROCKET_DATABASES='{my_db={url="db.sqlite"}}'
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Multiple databases can be specified in the `ROCKET_DATABASES` environment variable
|
||||||
|
//! as well by comma separating them:
|
||||||
|
//!
|
||||||
|
//! ```bash
|
||||||
|
//! ROCKET_DATABASES='{my_db={url="db.sqlite"},my_pg_db={url="postgres://root:root@localhost/my_pg_db"}}'
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! ## Guard Types
|
//! ## Guard Types
|
||||||
|
@ -203,6 +210,21 @@
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
//! Other databases can be used by specifying their respective [`Poolable`]
|
||||||
|
//! type:
|
||||||
|
//!
|
||||||
|
//! ```rust
|
||||||
|
//! # extern crate rocket;
|
||||||
|
//! # #[macro_use] extern crate rocket_contrib;
|
||||||
|
//! # #[cfg(feature = "postgres_pool")]
|
||||||
|
//! # mod test {
|
||||||
|
//! use rocket_contrib::databases::postgres;
|
||||||
|
//!
|
||||||
|
//! #[database("my_pg_db")]
|
||||||
|
//! struct MyPgDatabase(postgres::Connection);
|
||||||
|
//! # }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
//! The macro generates a [`FromRequest`] implementation for the decorated type,
|
//! The macro generates a [`FromRequest`] implementation for the decorated type,
|
||||||
//! allowing the type to be used as a request guard. This implementation
|
//! allowing the type to be used as a request guard. This implementation
|
||||||
//! retrieves a connection from the database pool or fails with a
|
//! retrieves a connection from the database pool or fails with a
|
||||||
|
|
Loading…
Reference in New Issue