Skip to main content

Dialect

Enum Dialect 

Source
pub enum Dialect {
    Postgres,
    Sqlite,
    MySql,
}
Expand description

A supported database dialect.

Variants§

§

Postgres

§

Sqlite

§

MySql

Implementations§

Source§

impl Dialect

Source

pub fn from_database(database: &str) -> Self

Pick the dialect from the manifest’s stack.database ("sqlite" → SQLite, "mysql" → MySQL, else the Postgres default).

Source

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.

Source

pub fn app_generates_id(self) -> bool

Whether the app must generate id on insert (SQLite, MySQL) rather than the database (Postgres).

Source

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).

Source

pub fn column_type(self, ty: FieldType) -> &'static str

The SQL column type for a scalar field.

Source

pub fn timestamp_type_default(self) -> &'static str

The TYPE NOT NULL DEFAULT ... fragment for the created_at/updated_at columns.

Source

pub fn now_expr(self) -> &'static str

The SQL expression for “now” used in UPDATE ... SET updated_at = <now>.

Source

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).

Source

pub fn pool_type(self) -> &'static str

The sqlx pool type used in generated code.

Source

pub fn pool_options(self) -> &'static str

The sqlx pool-options type.

Source

pub fn sqlx_module(self) -> &'static str

The sqlx submodule the pool types live in (sqlx::postgres / sqlx::sqlite / sqlx::mysql).

Source

pub fn sqlx_feature(self) -> &'static str

The sqlx feature to enable in the generated Cargo.toml.

Source

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.

Source

pub fn example_url(self, project: &str) -> String

An example DATABASE_URL for .env.example.

Trait Implementations§

Source§

impl Clone for Dialect

Source§

fn clone(&self) -> Dialect

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Dialect

Source§

impl Debug for Dialect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Dialect

Source§

impl PartialEq for Dialect

Source§

fn eq(&self, other: &Dialect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Dialect

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.