Skip to main content

porm/
lib.rs

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