Skip to main content

Crate orbit_orm

Crate orbit_orm 

Source
Expand description

Orbit is an ORM for Rocket.rs apps. It supports MySQL and MariaDB, PostgreSQL and SQLite, each behind a Cargo feature of the same name. The database is chosen by the URL.

Orbit uses sqlx for the connection pool and the wire protocol, and adds the ORM layer on top of it.

Modules§

raw
Raw SQL, for statements that the query builder does not cover. Each function takes a &Database or a &mut Transaction, as the query builder’s terminal methods do.
schema
A database-neutral schema builder, after Laravel’s Schema::create, Schema::table and Blueprint.

Macros§

migrations
Embeds migrations in the binary at build time. dir is relative to the crate root, and each name is a folder in it with up.sql and down.sql. The names are listed by hand, and a missing file is a build error. Returns a Result<Migrator, Error>.

Structs§

Database
The connection pool for one database. Clone-free: share it behind an Arc or in Rocket’s state.
Migration
One migration: its name, and what applies it (up) and reverts it (down). Either fixed SQL (Migration::new, files) or schema statements (Migration::schema).
Migrator
The migrations of one app, sorted by name. Build it with Migrator::from_dir or migrations!.
PoolOptions
The settings for the connection pool, given to Database::connect_with. Default gives the settings that Database::connect uses.
Query
A query on one model’s table. Start it with Model::query() or Query::table(), then finish it with a terminal method such as get, first or insert.
Status
One line of Migrator::status.
Transaction
An open transaction, given to the closure of Database::transaction. Pass it to queries as &mut *tx. It commits or rolls back when that closure returns.

Enums§

Direction
The sort direction for order_by.
Driver
A database that Orbit can talk to. The variants are the enabled Cargo features.
Error
Any error from Orbit. Driver errors that have a variant here are classified; the rest come through unchanged as Database.
Operator
A comparison for where_op.
State
Whether a migration has run. Applied carries the batch it ran in.
Value
A value bound to a query. Orbit sends every value as a bind parameter, never as SQL text, except that PostgreSQL gets a NULL written into the SQL, since its parameters need a type.

Traits§

Executor
Where a query runs: a &Database, on a pooled connection, or a &mut Transaction, on the transaction’s connection. Terminal methods such as get take either.
Model
A table and the Rust type that its rows map to. Derive it with #[derive(OrbitModel)], or write it by hand.

Derive Macros§

OrbitModel
Implements FromRow and Model for a struct with named fields.