sea_orm_rocket_codegen/
lib.rs

1#![recursion_limit = "256"]
2#![warn(rust_2018_idioms)]
3
4//! # `sea_orm_rocket` - Code Generation
5//!
6//! Implements the code generation portion of the `sea_orm_rocket` crate. This
7//! is an implementation detail. This create should never be depended on
8//! directly.
9
10#[macro_use]
11extern crate quote;
12
13mod database;
14
15/// Automatic derive for the [`Database`] trait.
16///
17/// The derive generates an implementation of [`Database`] as follows:
18///
19/// * [`Database::NAME`] is set to the value in the `#[database("name")]`
20///   attribute.
21///
22///   This names the database, providing an anchor to configure the database via
23///   `Rocket.toml` or any other configuration source. Specifically, the
24///   configuration in `databases.name` is used to configure the driver.
25///
26/// * [`Database::Pool`] is set to the wrapped type: `PoolType` above. The type
27///   must implement [`Pool`].
28///
29/// To meet the required [`Database`] supertrait bounds, this derive also
30/// generates implementations for:
31///
32/// * `From<Db::Pool>`
33///
34/// * `Deref<Target = Db::Pool>`
35///
36/// * `DerefMut<Target = Db::Pool>`
37///
38/// * `FromRequest<'_> for &Db`
39///
40/// * `Sentinel for &Db`
41///
42/// The `Deref` impls enable accessing the database pool directly from
43/// references `&Db` or `&mut Db`. To force a dereference to the underlying
44/// type, use `&db.0` or `&**db` or their `&mut` variants.
45///
46/// [`Database`]: ../sea_orm_rocket/trait.Database.html
47/// [`Database::NAME`]: ../sea_orm_rocket/trait.Database.html#associatedconstant.NAME
48/// [`Database::Pool`]: ../sea_orm_rocket/trait.Database.html#associatedtype.Pool
49/// [`Pool`]: ../sea_orm_rocket/trait.Pool.html
50#[proc_macro_derive(Database, attributes(database))]
51pub fn derive_database(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
52    crate::database::derive_database(input)
53}