Porm
Porm is a new type of ORM for PostgreSQL. Instead of defining some models in Rust, Porm parse migration scripts and generate models from it.
[!WARNING] Porm currently in a pre-1.0 so prepare for a lot of breaking changes!
Features
- Lightweight.
- The generated models in a thin layer on top of tokio-postgres API.
- Database is a single source of truth.
- Built-in schema migration.
- Use actual parser from PostgreSQL.
How it works
Suppose you have the following migration scripts:
-- 0.sql
(
id serial NOT NULL,
title text NOT NULL,
body text NOT NULL,
PRIMARY KEY (id)
);
-- 1.sql
post ADD published boolean NOT NULL DEFAULT FALSE;
(published);
Porm will generate a corresponding struct for you:
The generated struct will have methods to query PostgreSQL based on table indexes:
Porm also generate a helper struct to insert a new row with default values:
Notice PostBuilder::new function that requires non-null columns without default value. The following code will insert a new row and construct Post value with id and published loaded from the database:
let post = new.create.await.unwrap;
assert_eq!; // Suppose this is the first row.
assert_eq!;
assert_eq!;
assert!;
Non-goals
- Synchronous API.
- Supports downgrade migration.
- Supports other databases.
Breaking changes in parser 0.3
ParseErrorno longer have migration version on every variants.- Migration version will be become a migration name if
Migration::namereturnNone.
Breaking changes in 0.2
Migration::nameno longer optional.Logger::runhas new signature.Error::ExecuteMigrationandError::UpdateVersionhas been updated.
License
This project is licensed under either of
- Apache License, Version 2.0
- MIT License
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Porm by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.