Trait QueryStatementWriter

pub trait QueryStatementWriter: QueryStatementBuilder {
    // Required method
    fn build_collect_into<T>(&self, query_builder: T, sql: &mut dyn SqlWriter)
       where T: QueryBuilder;

    // Provided methods
    fn to_string<T>(&self, query_builder: T) -> String
       where T: QueryBuilder { ... }
    fn build<T>(&self, query_builder: T) -> (String, Values)
       where T: QueryBuilder { ... }
    fn build_collect<T>(
        &self,
        query_builder: T,
        sql: &mut dyn SqlWriter,
    ) -> String
       where T: QueryBuilder { ... }
}

Required Methods§

fn build_collect_into<T>(&self, query_builder: T, sql: &mut dyn SqlWriter)
where T: QueryBuilder,

Provided Methods§

fn to_string<T>(&self, query_builder: T) -> String
where T: QueryBuilder,

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"#
);

fn build<T>(&self, query_builder: T) -> (String, Values)
where T: QueryBuilder,

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))])
);

fn build_collect<T>(&self, query_builder: T, sql: &mut dyn SqlWriter) -> String
where T: QueryBuilder,

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.

Implementors§