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’sColumnTypes map onto; the lengths are kept in the SQL because they document intent and cost nothing. integer primary keyis the row id itself, and auto-increments with no keyword.autoincrementexists 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§
impl Copy for Sqlite
Source§impl Dialect for Sqlite
impl Dialect for Sqlite
Source§fn skip_locked(&self) -> (&'static str, &'static str)
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
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 quote(&self, identifier: &str) -> String
fn quote(&self, identifier: &str) -> String
Source§fn placeholder(&self, _position: usize) -> String
fn placeholder(&self, _position: usize) -> String
position-th bound parameter, counting from 1.Source§fn column_type(&self, kind: &ColumnType) -> String
fn column_type(&self, kind: &ColumnType) -> String
Source§fn uuid_default(&self) -> Option<&'static str>
fn uuid_default(&self) -> Option<&'static str>
Source§fn returning(&self) -> ReturningStyle
fn returning(&self) -> ReturningStyle
Source§fn limit_offset(
&self,
limit: Option<i64>,
offset: Option<i64>,
_ordered: bool,
) -> String
fn limit_offset( &self, limit: Option<i64>, offset: Option<i64>, _ordered: bool, ) -> String
limit … offset …, in whatever form this database accepts. Read moreSource§fn supports_if_not_exists_index(&self) -> bool
fn supports_if_not_exists_index(&self) -> bool
create index if not exists is understood. Read moreSource§fn booleans_are_integers(&self) -> bool
fn booleans_are_integers(&self) -> bool
boolean column really is one. Read moreSource§fn max_identifier_length(&self) -> usize
fn max_identifier_length(&self) -> usize
Source§fn current_schema_expression(&self) -> &'static str
fn current_schema_expression(&self) -> &'static str
Source§fn list_tables_sql(&self) -> &'static str
fn list_tables_sql(&self) -> &'static str
Source§fn disable_foreign_keys_sql(&self) -> Option<&'static str>
fn disable_foreign_keys_sql(&self) -> Option<&'static str>
fn enable_foreign_keys_sql(&self) -> Option<&'static str>
Source§fn supports_if_not_exists_table(&self) -> bool
fn supports_if_not_exists_table(&self) -> bool
create table if not exists is understood.Source§fn migrations_table_sql(&self, table: &str) -> String
fn migrations_table_sql(&self, table: &str) -> String
Source§fn add_column_clause(&self) -> &'static str
fn add_column_clause(&self) -> &'static str
alter table. Read more