Skip to main content

Sqlite

Struct Sqlite 

Source
pub struct Sqlite;
Expand description

SQLite’s SQL.

This dialect compiles unconditionally; the driver beside it does not. A dialect is string formatting with no dependency at all, so the generated SQL can be asserted in a build that cannot open a SQLite file — which is how the other three are tested too.

SQLite is not a server and its SQL reflects that. Three differences are load-bearing:

  • Types are advisory. A column has a type affinity, not a type, and a varchar(255) accepts a megabyte. The affinities below are the ones the framework’s ColumnTypes map onto; the lengths are kept in the SQL because they document intent and cost nothing.
  • integer primary key is the row id itself, and auto-increments with no keyword. autoincrement exists but only stops row ids being reused after a delete, at the cost of a second table — which is not what the other three do, so it is not asked for here.
  • Foreign keys are off unless switched on per connection. That is a SQLite default, not a choice this dialect can make; the driver turns them on for every connection it opens.

Trait Implementations§

Source§

impl Clone for Sqlite

Source§

fn clone(&self) -> Sqlite

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 Sqlite

Source§

impl Debug for Sqlite

Source§

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

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

impl Default for Sqlite

Source§

fn default() -> Sqlite

Returns the “default value” for a type. Read more
Source§

impl Dialect for Sqlite

Source§

fn skip_locked(&self) -> (&'static str, &'static str)

Nothing, and here that is correct rather than missing. SQLite has no row locks — a write transaction locks the whole database — so two workers cannot both claim one job however the select is written. What makes it safe is begin immediate below, not a clause here.

Source§

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

begin immediate, not the bare begin the other three use.

SQLite’s default transaction is deferred: it takes a read lock on the first select and only tries to upgrade at the first write. Two transactions that both read and then both try to upgrade deadlock, and SQLite breaks the tie by failing one with SQLITE_BUSY immediately — without waiting for busy_timeout, because waiting cannot help. Two queue workers are exactly that shape.

begin immediate takes the write lock up front, so the second worker waits its turn instead of failing.

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. Read more
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. Read more
Source§

fn supports_if_not_exists_index(&self) -> bool

Whether create index if not exists is understood. Read more
Source§

fn booleans_are_integers(&self) -> bool

Whether a boolean column really is one. Read more
Source§

fn max_identifier_length(&self) -> usize

The longest identifier this database accepts.
Source§

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

The expression naming the schema this connection is working in. Read more
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. Read more
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 supports_if_not_exists_table(&self) -> bool

Whether create table if not exists is understood.
Source§

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

The DDL for the migration tracking table. Read more
Source§

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

How a column is added in an alter table. Read more
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 drop_table_sql(&self, table: &str) -> String

Drop one table, including anything depending on it.

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<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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.