Raw and Unprepared Statements
Raw SQL
Documentation and Examples in the docs
While it is highly recommended to use SeaQuery's generalized interface for creating queries, it is possible to convert raw SQL statements into queries that the API accepts, with:
sea_orm::Statement::from_string
sea_orm::Transaction::from_sql_and_values
sea_orm::Statement::from_sql_and_values
Note that they return Self
, so you can use the result in any situations where they are respectively accepted.
Also note that this method requires knowing the type of database backend you are using at compile time, and you are responsible for giving it the correct sql statements.
Unprepared SQL
This method might be vulnerable to SQL injection!
An unprepared SQL are ones that are directly sent to the database without being processed by the ORM. It is highly not recommended unless you can prove the statements' correctness and security.
To send an unprepared SQL statement:
#![allow(unused)] fn main() { let db: DatabaseConnection = { /* */ }; // One statement db.execute_unprepared("CREATE EXTENSION IF NOT EXISTS citext").await? // Multiple statements db.execute_unprepared("STATEMENT1; STATEMENT2; ...").await? }