Skip to main content

Query

Trait Query 

Source
pub trait Query: Expression {
    // Required methods
    fn query_type(&self) -> QueryType;
    fn dialect(&self) -> &dyn Dialect;

    // Provided methods
    fn build(&self) -> Result<(String, Vec<Value>)> { ... }
    fn build_from(&self, start: usize) -> Result<(String, Vec<Value>)> { ... }
}
Expand description

A complete, runnable statement.

An Expression is any fragment; a Query is a fragment that stands alone, knows which dialect it is written in and therefore can be built without being told anything. That is what lets q.build() take no arguments while a bare expression still needs build(dialect, expr).

A query is also an expression, so it nests as a sub-select — and because the placeholder counter belongs to the SqlWriter rather than to the query, nesting re-indexes on its own.

Required Methods§

Source

fn query_type(&self) -> QueryType

Which statement this renders.

Source

fn dialect(&self) -> &dyn Dialect

The dialect this query renders itself in.

bob’s BaseQuery carries its dialect the same way, and deliberately ignores the dialect handed to it when embedded in another query.

Provided Methods§

Source

fn build(&self) -> Result<(String, Vec<Value>)>

Render to SQL and arguments, numbering placeholders from 1.

The escape hatch that is always open: whatever layer produced the query, this hands back a String and a Vec<Value> and nothing else.

Source

fn build_from(&self, start: usize) -> Result<(String, Vec<Value>)>

build with a different first placeholder position, for splicing into a statement that already has arguments — bob’s BuildN.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§