pub enum Dialect {
Postgres,
Sqlite,
MySql,
}Expand description
A supported database dialect.
Variants§
Implementations§
Source§impl Dialect
impl Dialect
Sourcepub fn from_database(database: &str) -> Self
pub fn from_database(database: &str) -> Self
Pick the dialect from the manifest’s stack.database ("sqlite" → SQLite,
"mysql" → MySQL, else the Postgres default).
Sourcepub fn id_pk_ddl(self) -> &'static str
pub fn id_pk_ddl(self) -> &'static str
The id primary-key column DDL (no trailing comma). Postgres generates the UUID in the
database; SQLite and MySQL have no UUID generator, so the app supplies it on insert.
MySQL uses BINARY(16) — the type sqlx encodes/decodes uuid::Uuid to natively, so the
generated model, binds and FromRow stay uniform across dialects.
Sourcepub fn app_generates_id(self) -> bool
pub fn app_generates_id(self) -> bool
Whether the app must generate id on insert (SQLite, MySQL) rather than the database
(Postgres).
Sourcepub fn supports_returning(self) -> bool
pub fn supports_returning(self) -> bool
Whether the dialect supports INSERT/UPDATE ... RETURNING *. Postgres and SQLite do;
MySQL does not, so the generated repository re-reads the row with a SELECT after
writing (it knows the id, which the app generates).
Sourcepub fn column_type(self, ty: FieldType) -> &'static str
pub fn column_type(self, ty: FieldType) -> &'static str
The SQL column type for a scalar field.
Sourcepub fn timestamp_type_default(self) -> &'static str
pub fn timestamp_type_default(self) -> &'static str
The TYPE NOT NULL DEFAULT ... fragment for the created_at/updated_at columns.
Sourcepub fn now_expr(self) -> &'static str
pub fn now_expr(self) -> &'static str
The SQL expression for “now” used in UPDATE ... SET updated_at = <now>.
Sourcepub fn placeholder(self, n: usize) -> String
pub fn placeholder(self, n: usize) -> String
A bind placeholder for parameter n (1-based): $n on Postgres, ?n on SQLite, and a
bare positional ? on MySQL (its protocol binds positionally, without an index).
Sourcepub fn pool_options(self) -> &'static str
pub fn pool_options(self) -> &'static str
The sqlx pool-options type.
Sourcepub fn sqlx_module(self) -> &'static str
pub fn sqlx_module(self) -> &'static str
The sqlx submodule the pool types live in (sqlx::postgres / sqlx::sqlite /
sqlx::mysql).
Sourcepub fn sqlx_feature(self) -> &'static str
pub fn sqlx_feature(self) -> &'static str
The sqlx feature to enable in the generated Cargo.toml.
Sourcepub fn integrity_error_mapping(self) -> String
pub fn integrity_error_mapping(self) -> String
The full if let sqlx::Error::Database(..) { .. } block, inside From<sqlx::Error>, that
classifies a database integrity error into Error::Conflict (unique violation) or
Error::ForeignKey. Indented to sit at the 8-space body level of the from function.
Postgres and SQLite expose distinct codes through .code() (SQLSTATE / extended result
code). MySQL collapses both to SQLSTATE 23000, so it must read the numeric error code
(1062 duplicate key, 1452 foreign key) off the concrete MySqlDatabaseError.
Sourcepub fn example_url(self, project: &str) -> String
pub fn example_url(self, project: &str) -> String
An example DATABASE_URL for .env.example.
Trait Implementations§
impl Copy for Dialect
impl Eq for Dialect
impl StructuralPartialEq for Dialect
Auto Trait Implementations§
impl Freeze for Dialect
impl RefUnwindSafe for Dialect
impl Send for Dialect
impl Sync for Dialect
impl Unpin for Dialect
impl UnsafeUnpin for Dialect
impl UnwindSafe for Dialect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.