pub trait Dialect:
Debug
+ Send
+ Sync {
// Required methods
fn write_arg(&self, w: &mut SqlWriter<'_>, position: usize);
fn write_quoted(&self, w: &mut SqlWriter<'_>, s: &str);
// Provided method
fn write_named_arg(&self, w: &mut SqlWriter<'_>, _name: &str) { ... }
}Expand description
The per-database syntax an expression needs in order to render itself.
The three dialects keelson targets differ only in these decisions:
| dialect | placeholder | quote | named |
|---|---|---|---|
| PostgreSQL | $1 | "id" | unsupported |
| MySQL | ? (position ignored) | `id` | unsupported |
| SQLite | ?1 | "id" | :name |
bob splits named-argument support into a second DialectWithNamed interface
and type-asserts on it. We keep one trait with a defaulted method instead, so
resolution stays static and “this dialect cannot do that” is one recorded
error rather than a failed downcast.
All three methods are infallible. They append to the writer’s buffer, and
writing into a String cannot fail; the one real failure — a named argument
asked of a dialect that has none — is recorded on the writer with
SqlWriter::record_error and surfaced later by build.
§Implementing
Write only through SqlWriter::push_str. Never call
SqlWriter::push_arg from inside write_arg: that is
the method push_arg calls, and it is the only place the placeholder counter
advances.
Required Methods§
Sourcefn write_arg(&self, w: &mut SqlWriter<'_>, position: usize)
fn write_arg(&self, w: &mut SqlWriter<'_>, position: usize)
Write the placeholder for the argument at position (1-based).
A dialect with positional placeholders ignores position — the argument
order carries the meaning instead.
Sourcefn write_quoted(&self, w: &mut SqlWriter<'_>, s: &str)
fn write_quoted(&self, w: &mut SqlWriter<'_>, s: &str)
Write s as a quoted identifier, including the quote characters.
Provided Methods§
Sourcefn write_named_arg(&self, w: &mut SqlWriter<'_>, _name: &str)
fn write_named_arg(&self, w: &mut SqlWriter<'_>, _name: &str)
Write the placeholder for a named argument.
Defaults to recording Error::NoNamedArgs; only SQLite overrides it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".