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§
pub extern crate async_trait;
pub extern crate crash_orm_derive as derive;
pub extern crate tokio_postgres as postgres;
pub use crate::error::*;
Modules§
- Contains traits defining columns as typed or untyped traits.
- Contains the ColumnType trait.
- Types
- Contains the definition of a connection supported by the ORM.
- Entity
- Contains the definition of a column of an entity.
- Contains utility functions for vectors of entities.
- Contains an error enum for all types of errors in the ORM.
- migration
migration
Migration - Reexports all required modules and crates
- Query
- Contains the definition of query conditions.
- Entity Relations
- Contains the trait for mapping a Row into an object.
- Schema
- See VirtualColumn.