Crate crash_orm

Source
Expand description

§Crash ORM

Crash ORM is an async database ORM built for Postgres.

The ORM is still in heavy development and bugs might occur. There may also be breaking changes to the library in minor versions without further notice.

§Documentation

§Request changes for documentation

Please open an issue with the “Documentation” Template.

You can also directly open a pull request with the changes you propose.

§Getting Started

This ORM only works with Postgres. The ORM requires you to have a working installation of Postgres.

To connect to postgres, you will need a connection string based on the following structure:

postgresql://user:password@netloc/dbname

§Create the CrashOrmDatabaseConnection

The first thing you want to do is creating the CrashOrmDatabaseConnection.

 use crash_orm::postgres::NoTls;
 use crash_orm::prelude::*;

 let conn = CrashOrmDatabaseConnection::new("postgresql://<user>:<password>@<netloc>/<dbname>", NoTls).await
     .expect("Failed to connect to database");

This connection is mandatory for all functions on entities.

You should store this variable globally or in case of a web framework like actix you can add it as web::Data.

§Your first Entity

You can now declare your first Entity.

use crash_orm::derive::{Entity, Schema};

#[derive(Debug, Entity, Schema)]
struct Person {
    id: Option<u32>,
    name: String,
}

This will generate a lot of code, if you are curious, you can inspect this struct with ‘cargo expand’.

For more info, visit the corresponding docs mentioned above.

Re-exports§

Modules§