[][src]Trait quaint::visitor::Visitor

pub trait Visitor<'a> {
    const C_BACKTICK: &'static str;
    const C_WILDCARD: &'static str;

    fn build<Q>(query: Q) -> (String, Vec<ParameterizedValue<'a>>)
    where
        Q: Into<Query<'a>>
;
fn write<D: Display>(&mut self, s: D) -> Result;
fn add_parameter(&mut self, value: ParameterizedValue<'a>);
fn visit_limit_and_offset(
        &mut self,
        limit: Option<ParameterizedValue<'a>>,
        offset: Option<ParameterizedValue<'a>>
    ) -> Result;
fn visit_insert(&mut self, insert: Insert<'a>) -> Result;
fn parameter_substitution(&mut self) -> Result;
fn visit_aggregate_to_string(&mut self, value: DatabaseValue<'a>) -> Result; fn surround_with<F>(&mut self, begin: &str, end: &str, f: F) -> Result
    where
        F: FnOnce(&mut Self) -> Result
, { ... }
fn visit_parameterized(&mut self, value: ParameterizedValue<'a>) -> Result { ... }
fn visit_joins(&mut self, joins: Vec<Join<'a>>) -> Result { ... }
fn visit_join_data(&mut self, data: JoinData<'a>) -> Result { ... }
fn visit_select(&mut self, select: Select<'a>) -> Result { ... }
fn visit_update(&mut self, update: Update<'a>) -> Result { ... }
fn visit_delete(&mut self, delete: Delete<'a>) -> Result { ... }
fn delimited_identifiers(&mut self, parts: &[&str]) -> Result { ... }
fn visit_query(&mut self, query: Query<'a>) { ... }
fn visit_union(&mut self, ua: Union<'a>) -> Result { ... }
fn visit_columns(&mut self, columns: Vec<DatabaseValue<'a>>) -> Result { ... }
fn visit_operation(&mut self, op: SqlOp<'a>) -> Result { ... }
fn visit_database_value(&mut self, value: DatabaseValue<'a>) -> Result { ... }
fn visit_table(&mut self, table: Table<'a>, include_alias: bool) -> Result { ... }
fn visit_column(&mut self, column: Column<'a>) -> Result { ... }
fn visit_row(&mut self, row: Row<'a>) -> Result { ... }
fn visit_conditions(&mut self, tree: ConditionTree<'a>) -> Result { ... }
fn visit_expression(&mut self, expression: Expression<'a>) -> Result { ... }
fn visit_compare(&mut self, compare: Compare<'a>) -> Result { ... }
fn visit_ordering(&mut self, ordering: Ordering<'a>) -> Result { ... }
fn visit_grouping(&mut self, grouping: Grouping<'a>) -> Result { ... }
fn visit_function(&mut self, fun: Function<'a>) -> Result { ... }
fn visit_partitioning(&mut self, over: Over<'a>) -> Result { ... } }

A function travelling through the query AST, building the final query string and gathering parameters sent to the database together with the query.

Associated Constants

const C_BACKTICK: &'static str

Backtick character to surround identifiers, such as column and table names.

const C_WILDCARD: &'static str

Wildcard character to be used in LIKE queries.

Loading content...

Required methods

fn build<Q>(query: Q) -> (String, Vec<ParameterizedValue<'a>>) where
    Q: Into<Query<'a>>, 

Convert the given Query to an SQL string and a vector of parameters. When certain parameters are replaced with the C_PARAM character in the query, the vector should contain the parameter value in the right position.

The point of entry for visiting query ASTs.

let query = Select::from_table("cats");
let (sqlite, _) = Sqlite::build(query.clone());
let (psql, _) = Postgres::build(query.clone());
let (mysql, _) = Mysql::build(query.clone());

assert_eq!("SELECT `cats`.* FROM `cats`", sqlite);
assert_eq!("SELECT \"cats\".* FROM \"cats\"", psql);
assert_eq!("SELECT `cats`.* FROM `cats`", mysql);

fn write<D: Display>(&mut self, s: D) -> Result

Write to the query.

fn add_parameter(&mut self, value: ParameterizedValue<'a>)

When called, the visitor decided to not render the parameter into the query, replacing it with the C_PARAM, calling add_parameter with the replaced value.

fn visit_limit_and_offset(
    &mut self,
    limit: Option<ParameterizedValue<'a>>,
    offset: Option<ParameterizedValue<'a>>
) -> Result

The LIMIT and OFFSET statement in the query

fn visit_insert(&mut self, insert: Insert<'a>) -> Result

A walk through an INSERT statement

fn parameter_substitution(&mut self) -> Result

What to use to substitute a parameter in the query.

fn visit_aggregate_to_string(&mut self, value: DatabaseValue<'a>) -> Result

What to use to substitute a parameter in the query.

Loading content...

Provided methods

fn surround_with<F>(&mut self, begin: &str, end: &str, f: F) -> Result where
    F: FnOnce(&mut Self) -> Result

fn visit_parameterized(&mut self, value: ParameterizedValue<'a>) -> Result

A visit to a value we parameterize

fn visit_joins(&mut self, joins: Vec<Join<'a>>) -> Result

The join statements in the query

fn visit_join_data(&mut self, data: JoinData<'a>) -> Result

fn visit_select(&mut self, select: Select<'a>) -> Result

A walk through a SELECT statement

fn visit_update(&mut self, update: Update<'a>) -> Result

A walk through an UPDATE statement

fn visit_delete(&mut self, delete: Delete<'a>) -> Result

A walk through an DELETE statement

fn delimited_identifiers(&mut self, parts: &[&str]) -> Result

A helper for delimiting an identifier, surrounding every part with C_BACKTICK and delimiting the values with a .

fn visit_query(&mut self, query: Query<'a>)

A walk through a complete Query statement

fn visit_union(&mut self, ua: Union<'a>) -> Result

A walk through a union of SELECT statements

fn visit_columns(&mut self, columns: Vec<DatabaseValue<'a>>) -> Result

The selected columns

fn visit_operation(&mut self, op: SqlOp<'a>) -> Result

fn visit_database_value(&mut self, value: DatabaseValue<'a>) -> Result

A visit to a value used in an expression

fn visit_table(&mut self, table: Table<'a>, include_alias: bool) -> Result

A database table identifier

fn visit_column(&mut self, column: Column<'a>) -> Result

A database column identifier

fn visit_row(&mut self, row: Row<'a>) -> Result

A row of data used as an expression

fn visit_conditions(&mut self, tree: ConditionTree<'a>) -> Result

A walk through the query conditions

fn visit_expression(&mut self, expression: Expression<'a>) -> Result

An expression that can either be a single value, a set of conditions or a comparison call

fn visit_compare(&mut self, compare: Compare<'a>) -> Result

A comparison expression

fn visit_ordering(&mut self, ordering: Ordering<'a>) -> Result

A visit in the ORDER BY section of the query

fn visit_grouping(&mut self, grouping: Grouping<'a>) -> Result

A visit in the GROUP BY section of the query

fn visit_function(&mut self, fun: Function<'a>) -> Result

fn visit_partitioning(&mut self, over: Over<'a>) -> Result

Loading content...

Implementors

impl<'a> Visitor<'a> for Mysql<'a>[src]

impl<'a> Visitor<'a> for Postgres<'a>[src]

impl<'a> Visitor<'a> for Sqlite<'a>[src]

Loading content...