1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! ORM for PostgreSQL based on SQL migration scripts.
//!
//! # Quickstart
//! The first step is adding [tokio-postgres](https://crates.io/crates/tokio-postgres) to your
//! project and connect to PostgreSQL. Then create a directory for migration scripts within your
//! project and create `0.sql` in that directory for initial version of database schema.
//!
//! ## Create build scripts
//! Add [porm-parser](https://crates.io/crates/porm-parser) as a build dependency and create
//! `build.rs` with the following content:
//!
//! ```ignore
//! use porm_parser::parse_for_build_script;
//!
//! fn main() {
//! parse_for_build_script("PATH_TO_MIGRATION_SCRIPTS", |p| {
//! p.file_stem()
//! .unwrap()
//! .to_str()
//! .ok_or("file stem is not UTF-8")?
//! .parse::<u32>()
//! .map_err(|e| e.into())
//! })
//! .unwrap();
//! }
//! ```
//!
//! Replace `PATH_TO_MIGRATION_SCRIPTS` with path to the directory to have created.
//!
//! ## Include generated models
//! Add [porm](https://crates.io/crates/porm) as a dependency and create a module with the following
//! content:
//!
//! ```ignore
//! #![allow(unused)]
//!
//! porm::include_models!();
//! ```
//!
//! Then you can access the generated model via this module.
//!
//! ## Apply migration scripts
//! Use [crate::migration::migrate()] to apply migration scripts. Pass `MIGRATIONS` from the above
//! module as a last arguments.
/// Include models that was generated by [porm-parser](https://crates.io/crates/porm-parser).
///
/// This will pull generated models into the calling module. This also pull migration list to be
/// used with [migrate](crate::migration::migrate()).
///
/// Environment variable `PORM_GENERATED_FILE` must be set to the generated file.
pub use include_models;