
pg-worm
PostgreSQL's Worst ORM
pg-worm is an opiniated, straightforward, async ORM for PostgreSQL servers.
Well, at least that's the goal.
This library is based on tokio_postgres
and is intended to be used with tokio.
Usage
Fortunately, using this library is very easy.
Just derive the Model trait for your type, connect to your database
and you are ready to go!
Here's a quick example:
use pg_worm::{register, connect, NoTls, Model};
#[derive(Model)]
#[table(table_name = "users")] struct User {
#[column(primary_key, auto)] id: i64,
#[column(unique)] name: String,
#[column(column_name = "pwd_hash")] password: String
}
#[tokio::main]
async fn main() -> Result<(), pg_worm::Error> {
let conn = connect("postgres://me:me@localhost:5432", NoTls).await?;
tokio::spawn(async move { conn.await.expect("unable to connect") });
register!(User).await.unwrap();
User::insert("Bob", "very_hashed_password").await?;
User::insert("Kate".to_string(), "another_hashed_password").await?;
let all_users: Vec<User> = User::select().await;
assert_eq!(all_users.len(), 2);
let first_user: Option<User> = User::select_one().await;
assert!(first_user.is_some());
assert_eq!(first_user.unwrap().name, "Bob");
Ok(())
}