Expand description
ORM for PostgreSQL based on SQL migration scripts.
§Quickstart
The first step is adding 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 as a build dependency and create
build.rs with the following content:
ⓘ
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 as a dependency and create a module with the following content:
ⓘ
#![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.
Modules§
- migration
- Migration management.
Macros§
- include_
models - Include models that was generated by porm-parser.