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