pub trait QueryStatementWriter: QueryStatementBuilder {
// Required method
fn build_collect_into<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
);
// Provided methods
fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String { ... }
fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values) { ... }
fn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
) -> String { ... }
}
Required Methods§
fn build_collect_into<T: QueryBuilder>( &self, query_builder: T, sql: &mut dyn SqlWriter, )
Provided Methods§
sourcefn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
Build corresponding SQL statement for certain database backend and return SQL string
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.column(Glyph::Aspect)
.from(Glyph::Table)
.and_where(Expr::expr(Expr::col(Glyph::Aspect).if_null(0)).gt(2))
.order_by(Glyph::Image, Order::Desc)
.order_by((Glyph::Table, Glyph::Aspect), Order::Asc)
.to_string(MysqlQueryBuilder);
assert_eq!(
query,
r#"SELECT `aspect` FROM `glyph` WHERE IFNULL(`aspect`, 0) > 2 ORDER BY `image` DESC, `glyph`.`aspect` ASC"#
);
sourcefn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
Build corresponding SQL statement for certain database backend and collect query parameters into a vector
§Examples
use sea_query::{*, tests_cfg::*};
let (query, params) = Query::select()
.column(Glyph::Aspect)
.from(Glyph::Table)
.and_where(Expr::expr(Expr::col(Glyph::Aspect).if_null(0)).gt(2))
.order_by(Glyph::Image, Order::Desc)
.order_by((Glyph::Table, Glyph::Aspect), Order::Asc)
.build(MysqlQueryBuilder);
assert_eq!(
query,
r#"SELECT `aspect` FROM `glyph` WHERE IFNULL(`aspect`, ?) > ? ORDER BY `image` DESC, `glyph`.`aspect` ASC"#
);
assert_eq!(
params,
Values(vec![Value::Int(Some(0)), Value::Int(Some(2))])
);
sourcefn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
) -> String
fn build_collect<T: QueryBuilder>( &self, query_builder: T, sql: &mut dyn SqlWriter, ) -> String
Build corresponding SQL statement for certain database backend and collect query parameters
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.column(Glyph::Aspect)
.from(Glyph::Table)
.and_where(Expr::expr(Expr::col(Glyph::Aspect).if_null(0)).gt(2))
.order_by(Glyph::Image, Order::Desc)
.order_by((Glyph::Table, Glyph::Aspect), Order::Asc)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `aspect` FROM `glyph` WHERE IFNULL(`aspect`, 0) > 2 ORDER BY `image` DESC, `glyph`.`aspect` ASC"#
);
let (placeholder, numbered) = MysqlQueryBuilder.placeholder();
let mut sql = SqlWriterValues::new(placeholder, numbered);
assert_eq!(
query.build_collect(MysqlQueryBuilder, &mut sql),
r#"SELECT `aspect` FROM `glyph` WHERE IFNULL(`aspect`, ?) > ? ORDER BY `image` DESC, `glyph`.`aspect` ASC"#
);
let (sql, values) = sql.into_parts();
assert_eq!(
values,
Values(vec![Value::Int(Some(0)), Value::Int(Some(2))])
);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.