Skip to main content

statement

Function statement 

Source
pub fn statement(sql: impl Into<String>) -> Statement
Expand description

Runs sql as written, as Laravel’s DB::statement inside a migration.

The SQL is database-specific: Orbit does not check, quote or translate it, and runs the same string on every database. Use it for data rows (seeding a role, moving values between columns) and for what the builder cannot express, such as a MySQL-only column type. Add only when the SQL is for one database family. Orbit’s own generated code never uses it.

to_sql and try_to_sql return the string unchanged, as one statement. A wrong string is reported by the database when it runs. An empty string may do nothing, or be an error, depending on the database.

use orbit_orm::schema::{self, Dialect};

let seed = schema::statement("INSERT INTO roles (name) VALUES ('admin')");
let avatar = schema::statement("ALTER TABLE users MODIFY avatar MEDIUMBLOB").only(Dialect::MySql);