Expand description
A database-neutral schema builder, after Laravel’s Schema::create, Schema::table and
Blueprint.
A migration describes a table once and the same code runs on SQLite, MySQL and MariaDB, and PostgreSQL:
use orbit_orm::schema::{self, Action};
let posts = schema::create("posts", |t| {
t.id();
t.string("title");
t.text("body").nullable();
t.big_integer("user_id");
t.foreign("user_id").references("users", "id").on_delete(Action::Restrict);
t.unique(["title"]);
});
let rename = schema::table("posts", |t| {
t.string("subtitle").nullable();
t.rename_column("body", "content");
});A Statement is only a description. Statement::to_sql renders it for a Driver as a
list of statements to run in order: PostgreSQL and SQLite create a plain index with a separate
CREATE INDEX, and sqlx does not run several statements in one string on every database.
statement runs SQL as written, as Laravel’s DB::statement in a migration, and
Statement::only limits any statement to one database family.
Structs§
- Blueprint
- The columns and commands (indexes, keys, renames, drops) of a table, in the order they were added.
- Column
- A column of a table being created or changed. Chain
nullable,default,use_current,length,precision,primaryandchangeon it. - Foreign
Key - A foreign key under construction. Chain
references,on_delete,on_updateandname. - Index
- A plain or unique index under construction. Chain
nameto choose its name. - Statement
- A schema change, ready to render for any database.
Enums§
- Action
- What a foreign key does to this table’s rows when the referenced row is deleted or updated.
- Dialect
- A database family. A
Drivermaps to one of these. UnlikeDriver, all three variants exist whatever Cargo features are on, so a migration can name any of them, for example inStatement::only.
Functions§
- create
- Creates a table. The closure describes its columns, indexes and foreign keys.
- create_
if_ not_ exists - Creates a table unless it exists:
CREATE TABLE IF NOT EXISTS. A plain index that PostgreSQL and SQLite create with a separate statement takesCREATE INDEX IF NOT EXISTS. - drop
- Drops a table. It is an error in the database if the table does not exist.
- drop_
if_ exists - Drops a table if it exists.
- statement
- Runs
sqlas written, as Laravel’sDB::statementinside a migration. - table
- Changes an existing table, as Laravel’s
Schema::table. A column described in the closure is added, or modified when it ends with.change();rename_columnanddrop_columnrename and drop columns;index,unique,primaryandforeignadd keys;drop_indexanddrop_foreigndrop them.