pub trait SqlDialect: Send + Sync {
Show 24 methods
// Required methods
fn identifier_quote(&self) -> Quote;
fn marker(&self, index: usize) -> String;
fn numbered_markers(&self) -> bool;
fn expression(
&self,
sql: String,
values: Vec<Value>,
) -> Result<Expr, RenderError>;
fn inline_values(
&self,
sql: &str,
values: &[Value],
) -> Result<String, RenderError>;
fn string_literal(&self, text: &str) -> String;
fn json_equals(
&self,
column: &str,
value: &Value,
negated: bool,
) -> BoundSql;
fn json_containment(
&self,
column: &str,
value: &Value,
containment: JsonContainment,
) -> BoundSql;
fn json_exists(
&self,
column: &str,
existence: JsonExistence,
target: &str,
negated: bool,
) -> Result<BoundSql, RenderError>;
fn array_predicate(
&self,
column: &str,
operator: ArrayOperator,
elements: Vec<Value>,
null_allowed: bool,
) -> BoundSql;
fn array_append(&self, column: &str, element: Value) -> BoundSql;
fn array_remove(
&self,
column: &str,
source: &str,
element: Value,
) -> BoundSql;
fn json_set(
&self,
column: &str,
path: &[JsonPathStep],
value: &Value,
) -> BoundSql;
fn exact_key(&self, column: &str) -> String;
// Provided methods
fn push_identifier(&self, out: &mut String, name: &str) { ... }
fn native_arrays(&self) -> bool { ... }
fn window_default(
&self,
function: &str,
column: &str,
offset: &str,
default: &str,
over: &str,
) -> String { ... }
fn open_limit(&self) -> Option<&'static str> { ... }
fn limit_in_subquery(&self) -> bool { ... }
fn groups_frames(&self) -> bool { ... }
fn update_limit(&self) -> bool { ... }
fn limit_offset(&self, limit: Option<u64>, offset: Option<u64>) -> BoundSql { ... }
fn literal_match(
&self,
column: &str,
literal: &str,
leading: bool,
trailing: bool,
) -> Result<BoundSql, RenderError> { ... }
fn in_list(&self, column: Expr, values: Vec<Value>, negated: bool) -> Expr { ... }
}Expand description
The SQL dialect of a backend, for SQL written as text.
column arguments are SQL already quoted. JSON is compared as PostgreSQL
compares jsonb on every backend: as documents, not text, so key order
and spacing do not count and 1 equals 1.0.
Required Methods§
Sourcefn identifier_quote(&self) -> Quote
fn identifier_quote(&self) -> Quote
The quotes around an identifier.
Sourcefn numbered_markers(&self) -> bool
fn numbered_markers(&self) -> bool
Whether markers are numbered ($1).
A fragment with numbered markers is renumbered when it is spliced
behind other values; one with positional ? markers is not.
Sourcefn expression(
&self,
sql: String,
values: Vec<Value>,
) -> Result<Expr, RenderError>
fn expression( &self, sql: String, values: Vec<Value>, ) -> Result<Expr, RenderError>
SQL written with this dialect’s markers, such as a raw fragment, as an
expression binding values to its markers in order. The dialect’s own
pieces need no reading: a BoundSql is an expression as it is.
A marker without a value, or a value without a marker, is an error.
Sourcefn inline_values(
&self,
sql: &str,
values: &[Value],
) -> Result<String, RenderError>
fn inline_values( &self, sql: &str, values: &[Value], ) -> Result<String, RenderError>
sql with values written in place of its markers, for display.
Sourcefn string_literal(&self, text: &str) -> String
fn string_literal(&self, text: &str) -> String
text as a quoted string literal, escaped as inline_values
writes one, for SQL that cannot bind it: DDL, or a constant an index
expression must match.
Sourcefn json_equals(&self, column: &str, value: &Value, negated: bool) -> BoundSql
fn json_equals(&self, column: &str, value: &Value, negated: bool) -> BoundSql
column holds the JSON document value, or does not when negated.
A NULL column matches neither the test nor its negation.
Sourcefn json_containment(
&self,
column: &str,
value: &Value,
containment: JsonContainment,
) -> BoundSql
fn json_containment( &self, column: &str, value: &Value, containment: JsonContainment, ) -> BoundSql
A JSON containment test of column against value.
Sourcefn json_exists(
&self,
column: &str,
existence: JsonExistence,
target: &str,
negated: bool,
) -> Result<BoundSql, RenderError>
fn json_exists( &self, column: &str, existence: JsonExistence, target: &str, negated: bool, ) -> Result<BoundSql, RenderError>
A JSON key- or path-existence test, or its negation.
Every backend reads a path strictly: a member step finds a member of an
object only, never of the objects inside an array, and an index step an
element of an array only. A key is the one-member path that names it,
so it exists only in an object. A member holding JSON null exists,
and a NULL column is unknown, so that the negation does not match it
either. A path with steps the backend cannot express is refused:
matching nothing, both the test and its negation, would hide the
mistake.
Sourcefn array_predicate(
&self,
column: &str,
operator: ArrayOperator,
elements: Vec<Value>,
null_allowed: bool,
) -> BoundSql
fn array_predicate( &self, column: &str, operator: ArrayOperator, elements: Vec<Value>, null_allowed: bool, ) -> BoundSql
An array predicate on column against the list elements.
elements are bound as native_arrays says,
and null_allowed says whether a contained-by list of native elements
also held a NULL, which elements leaves out.
Sourcefn array_append(&self, column: &str, element: Value) -> BoundSql
fn array_append(&self, column: &str, element: Value) -> BoundSql
column with element appended; a NULL column starts a new array.
Sourcefn array_remove(&self, column: &str, source: &str, element: Value) -> BoundSql
fn array_remove(&self, column: &str, source: &str, element: Value) -> BoundSql
column without the elements equal to element.
source is the column qualified with its table, for a subquery that
reads its elements.
Sourcefn json_set(
&self,
column: &str,
path: &[JsonPathStep],
value: &Value,
) -> BoundSql
fn json_set( &self, column: &str, path: &[JsonPathStep], value: &Value, ) -> BoundSql
column with the member or element at path set to value.
A path whose parent is missing (read strictly, as
json_exists reads a path), or is not the object
its member step needs or the array its index step needs, leaves the
document as it is, and an index past an array’s end appends the value.
Provided Methods§
Sourcefn push_identifier(&self, out: &mut String, name: &str)
fn push_identifier(&self, out: &mut String, name: &str)
Append name to out as a quoted identifier, doubling any quote inside it.
Sourcefn native_arrays(&self) -> bool
fn native_arrays(&self) -> bool
Whether an array column is the database’s own array type.
Its elements are then bound as values of the element type; elsewhere an
array is a JSON document and its elements are JSON values
(Value::Json).
Sourcefn window_default(
&self,
function: &str,
column: &str,
offset: &str,
default: &str,
over: &str,
) -> String
fn window_default( &self, function: &str, column: &str, offset: &str, default: &str, over: &str, ) -> String
LAG or LEAD (function) with a default, over the window over.
Sourcefn open_limit(&self) -> Option<&'static str>
fn open_limit(&self) -> Option<&'static str>
The limit an offset alone takes, where the dialect has no bare OFFSET.
Sourcefn limit_in_subquery(&self) -> bool
fn limit_in_subquery(&self) -> bool
Whether an IN (..) subquery may carry a LIMIT.
Sourcefn groups_frames(&self) -> bool
fn groups_frames(&self) -> bool
Whether a window frame may count GROUPS.
Sourcefn update_limit(&self) -> bool
fn update_limit(&self) -> bool
Whether an UPDATE takes ORDER BY and LIMIT itself. Where it does
not, a capped update is scoped through a primary-key subquery; the
builder renders an UpdateStatement’s limit
as it is told.
Sourcefn limit_offset(&self, limit: Option<u64>, offset: Option<u64>) -> BoundSql
fn limit_offset(&self, limit: Option<u64>, offset: Option<u64>) -> BoundSql
A query’s LIMIT n OFFSET ?.
The limit is written into the SQL, where SQLite 3.50+ would recompile a
statement with a bound LIMIT on every run, and the offset is bound, as a
u64 like a select’s, so paging reuses one statement.
Sourcefn literal_match(
&self,
column: &str,
literal: &str,
leading: bool,
trailing: bool,
) -> Result<BoundSql, RenderError>
fn literal_match( &self, column: &str, literal: &str, leading: bool, trailing: bool, ) -> Result<BoundSql, RenderError>
A test that column holds the text literal, preceded by anything
when leading and followed by anything when trailing: a LIKE
pattern with the literal’s %, _ and escape character escaped.
Refused when the backend cannot test literal as it is.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".