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
&Databaseor a&mut Transaction, as the query builder’s terminal methods do. - schema
- A database-neutral schema builder, after Laravel’s
Schema::create,Schema::tableandBlueprint.
Macros§
- migrations
- Embeds migrations in the binary at build time.
diris relative to the crate root, and each name is a folder in it withup.sqlanddown.sql. The names are listed by hand, and a missing file is a build error. Returns aResult<Migrator, Error>.
Structs§
- Database
- The connection pool for one database. Clone-free: share it behind an
Arcor 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_dirormigrations!. - Pool
Options - The settings for the connection pool, given to
Database::connect_with.Defaultgives the settings thatDatabase::connectuses. - Query
- A query on one model’s table. Start it with
Model::query()orQuery::table(), then finish it with a terminal method such asget,firstorinsert. - 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.
Appliedcarries 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
NULLwritten 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 asgettake 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§
- Orbit
Model - Implements
FromRowandModelfor a struct with named fields.