Skip to main content

Dialect

Trait Dialect 

Source
pub trait Dialect:
    Send
    + Sync
    + Debug
    + 'static {
Show 24 methods // Required methods fn name(&self) -> &'static str; fn quote(&self, identifier: &str) -> String; fn placeholder(&self, position: usize) -> String; fn column_type(&self, kind: &ColumnType) -> String; fn now(&self) -> &'static str; fn uuid_default(&self) -> Option<&'static str>; fn returning(&self) -> ReturningStyle; fn limit_offset( &self, limit: Option<i64>, offset: Option<i64>, ordered: bool, ) -> String; fn current_schema_expression(&self) -> &'static str; fn list_tables_sql(&self) -> &'static str; // Provided methods fn supports_if_not_exists_table(&self) -> bool { ... } fn supports_if_not_exists_index(&self) -> bool { ... } fn booleans_are_integers(&self) -> bool { ... } fn max_identifier_length(&self) -> usize { ... } fn migrations_table_sql(&self, table: &str) -> String { ... } fn add_column_clause(&self) -> &'static str { ... } fn begin_sql(&self) -> &'static str { ... } fn commit_sql(&self) -> &'static str { ... } fn rollback_sql(&self) -> &'static str { ... } fn savepoint_sql(&self, name: &str) -> String { ... } fn rollback_to_savepoint_sql(&self, name: &str) -> String { ... } fn disable_foreign_keys_sql(&self) -> Option<&'static str> { ... } fn enable_foreign_keys_sql(&self) -> Option<&'static str> { ... } fn drop_table_sql(&self, table: &str) -> String { ... }
}
Expand description

The differences between one SQL database and another.

Required Methods§

Source

fn name(&self) -> &'static str

postgres, mysql, sqlserver.

Source

fn quote(&self, identifier: &str) -> String

Wrap one identifier so a keyword or an unusual name is still valid.

The identifier has already been validated; this only quotes it.

Source

fn placeholder(&self, position: usize) -> String

The placeholder for the position-th bound parameter, counting from 1.

Source

fn column_type(&self, kind: &ColumnType) -> String

The type name for a logical column type.

Source

fn now(&self) -> &'static str

The expression for “now”, used by timestamps().

Source

fn uuid_default(&self) -> Option<&'static str>

The expression that generates a UUID, when the database has one.

Source

fn returning(&self) -> ReturningStyle

How a generated key comes back from an insert.

Source

fn limit_offset( &self, limit: Option<i64>, offset: Option<i64>, ordered: bool, ) -> String

limit … offset …, in whatever form this database accepts.

ordered says whether the query already has an order by, because SQL Server’s paging syntax requires one and will not accept paging without.

Source

fn current_schema_expression(&self) -> &'static str

The expression naming the schema this connection is working in.

information_schema is standard; the way you ask “which schema am I in” is not.

Source

fn list_tables_sql(&self) -> &'static str

A query returning one row per table in the current schema, with the name in the first column.

migrate:fresh enumerates and drops rather than running one clever statement, because only PostgreSQL has an anonymous block to put a loop in — and the enumerate-then-drop shape works identically everywhere.

Provided Methods§

Source

fn supports_if_not_exists_table(&self) -> bool

Whether create table if not exists is understood.

Source

fn supports_if_not_exists_index(&self) -> bool

Whether create index if not exists is understood.

PostgreSQL has it; MySQL and SQL Server do not, so the schema builder emits a plain create index and a repeated migration would fail — which is correct, since migrations run once.

Source

fn booleans_are_integers(&self) -> bool

Whether a boolean column really is one.

MySQL stores it as tinyint(1) and SQL Server as bit, so both hand back a number where PostgreSQL hands back a boolean. The row decoder uses this to convert.

Source

fn max_identifier_length(&self) -> usize

The longest identifier this database accepts.

Source

fn migrations_table_sql(&self, table: &str) -> String

The DDL for the migration tracking table.

The key column has to say primary key: MySQL refuses an auto_increment column that is not one, and a real server is the only thing that will tell you so.

Source

fn add_column_clause(&self) -> &'static str

How a column is added in an alter table.

PostgreSQL and MySQL say add column; SQL Server rejects the keyword on add while requiring it on drop, which is asymmetric enough that nobody guesses it right.

Source

fn begin_sql(&self) -> &'static str

Start a transaction.

T-SQL wants the word transaction; the others are happy with begin alone and reject begin transaction is fine there too, but the bare form is what their documentation uses.

Source

fn commit_sql(&self) -> &'static str

Source

fn rollback_sql(&self) -> &'static str

Source

fn savepoint_sql(&self, name: &str) -> String

Source

fn rollback_to_savepoint_sql(&self, name: &str) -> String

Source

fn disable_foreign_keys_sql(&self) -> Option<&'static str>

Turn off foreign key enforcement while tables are being dropped, so the order they come back in does not matter.

Source

fn enable_foreign_keys_sql(&self) -> Option<&'static str>

Source

fn drop_table_sql(&self, table: &str) -> String

Drop one table, including anything depending on it.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§