Expand description
Defines an SQL statement
Fields§
§sql: String
The SQL query
values: Option<Values>
The values for the SQL statement’s parameters
db_backend: DbBackend
The database backend this statement is constructed for. The SQL dialect and values should be valid for the DbBackend.
Implementations§
source§impl Statement
impl Statement
sourcepub fn from_string(db_backend: DbBackend, stmt: String) -> Statement
pub fn from_string(db_backend: DbBackend, stmt: String) -> Statement
Create a Statement from a crate::DatabaseBackend and a raw SQL statement
Examples found in repository?
src/database/mock.rs (lines 319-322)
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
fn init() -> Self {
Self {
stmts: vec![Statement::from_string(
DbBackend::Postgres,
"BEGIN".to_owned(),
)],
transaction_depth: 0,
}
}
fn begin_nested(&mut self, db_backend: DbBackend) {
self.transaction_depth += 1;
self.push(Statement::from_string(
db_backend,
format!("SAVEPOINT savepoint_{}", self.transaction_depth),
));
}
fn commit(&mut self, db_backend: DbBackend) -> bool {
if self.transaction_depth == 0 {
self.push(Statement::from_string(db_backend, "COMMIT".to_owned()));
true
} else {
self.push(Statement::from_string(
db_backend,
format!("RELEASE SAVEPOINT savepoint_{}", self.transaction_depth),
));
self.transaction_depth -= 1;
false
}
}
fn rollback(&mut self, db_backend: DbBackend) -> bool {
if self.transaction_depth == 0 {
self.push(Statement::from_string(db_backend, "ROLLBACK".to_owned()));
true
} else {
self.push(Statement::from_string(
db_backend,
format!("ROLLBACK TO SAVEPOINT savepoint_{}", self.transaction_depth),
));
self.transaction_depth -= 1;
false
}
}
sourcepub fn from_sql_and_values<I>(db_backend: DbBackend, sql: &str, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
pub fn from_sql_and_values<I>(db_backend: DbBackend, sql: &str, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
Create a SQL statement from a crate::DatabaseBackend, a raw SQL statement and param values