miniorm-example-transactions

Crates.iominiorm-example-transactions
lib.rsminiorm-example-transactions
version0.3.0
sourcesrc
created_at2024-03-15 17:54:54.816747
updated_at2024-03-15 18:30:17.509986
descriptiona *very* simple ORM built on top of sqlx
homepagehttps://github.com/meuter/miniorm-rs
repositoryhttps://github.com/meuter/miniorm-rs
max_upload_size
id1174998
size61,142
Cédric Meuter (meuter)

documentation

README

miniorm

Build Test Clippy Doc

Crates.io Docs.rs Crates.io Crates.io

The miniorm crate provides a very simple ORM on top of sqlx.

sqlx already provides a FromRow trait that can be derived automatically in order to convert a row from the database into an object. Howver, there is no corresponding ToRow macro that would allow convert an object back into a row to be inserted into the database.

This is where miniorm comes in. It provides a trait Schema that can also be automatically derived to describe the schema of the table that should be used for a given entity (i.e. struct).

Any struct that implements the FromRow and Schema traits can be used to create a CrudStore that provide the so-called "CRUD" operations:

  • (C)reate
  • (R)ead
  • (U)pdate
  • (D)elete

At the moment, miniorm only supports the postgres backend. Other backends could be provided in the future.

Examples

use sqlx::FromRow;
use miniorm::Schema;

#[derive(Debug, Clone, Eq, PartialEq, FromRow, Schema)]
struct Todo {
    #[column(TEXT NOT NULL)]
    description: String,

    #[column(BOOLEAN NOT NULL DEFAULT false)]
    done: bool,
}

For more complete examples, see:

Commit count: 95

cargo fmt