diesel/sqlite/
backend.rs

1//! The SQLite backend
2
3use super::connection::{SqliteBindCollector, SqliteValue};
4use super::query_builder::SqliteQueryBuilder;
5use crate::backend::*;
6use crate::sql_types::TypeMetadata;
7
8/// The SQLite backend
9#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
10pub struct Sqlite;
11
12/// Determines how a bind parameter is given to SQLite
13///
14/// Diesel deals with bind parameters after serialization as opaque blobs of
15/// bytes. However, SQLite instead has several functions where it expects the
16/// relevant C types.
17///
18/// The variants of this struct determine what bytes are expected from
19/// `ToSql` impls.
20#[allow(missing_debug_implementations)]
21#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
22pub enum SqliteType {
23    /// Bind using `sqlite3_bind_blob`
24    Binary,
25    /// Bind using `sqlite3_bind_text`
26    Text,
27    /// `bytes` should contain an `f32`
28    Float,
29    /// `bytes` should contain an `f64`
30    Double,
31    /// `bytes` should contain an `i16`
32    SmallInt,
33    /// `bytes` should contain an `i32`
34    Integer,
35    /// `bytes` should contain an `i64`
36    Long,
37}
38
39impl Backend for Sqlite {
40    type QueryBuilder = SqliteQueryBuilder;
41    type RawValue<'a> = SqliteValue<'a, 'a, 'a>;
42    type BindCollector<'a> = SqliteBindCollector<'a>;
43}
44
45impl TypeMetadata for Sqlite {
46    type TypeMetadata = SqliteType;
47    type MetadataLookup = ();
48}
49
50impl SqlDialect for Sqlite {
51    #[cfg(not(feature = "returning_clauses_for_sqlite_3_35"))]
52    type ReturningClause = sql_dialect::returning_clause::DoesNotSupportReturningClause;
53    #[cfg(feature = "returning_clauses_for_sqlite_3_35")]
54    type ReturningClause = SqliteReturningClause;
55
56    type OnConflictClause = SqliteOnConflictClause;
57
58    type InsertWithDefaultKeyword =
59        sql_dialect::default_keyword_for_insert::DoesNotSupportDefaultKeyword;
60    type BatchInsertSupport = SqliteBatchInsert;
61    type ConcatClause = sql_dialect::concat_clause::ConcatWithPipesClause;
62    type DefaultValueClauseForInsert = sql_dialect::default_value_clause::AnsiDefaultValueClause;
63
64    type EmptyFromClauseSyntax = sql_dialect::from_clause_syntax::AnsiSqlFromClauseSyntax;
65    type SelectStatementSyntax = sql_dialect::select_statement_syntax::AnsiSqlSelectStatement;
66
67    type ExistsSyntax = sql_dialect::exists_syntax::AnsiSqlExistsSyntax;
68    type ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison;
69    type AliasSyntax = sql_dialect::alias_syntax::AsAliasSyntax;
70}
71
72impl DieselReserveSpecialization for Sqlite {}
73impl TrustedBackend for Sqlite {}
74
75#[derive(Debug, Copy, Clone)]
76pub struct SqliteOnConflictClause;
77
78impl sql_dialect::on_conflict_clause::SupportsOnConflictClause for SqliteOnConflictClause {}
79impl sql_dialect::on_conflict_clause::PgLikeOnConflictClause for SqliteOnConflictClause {}
80
81#[derive(Debug, Copy, Clone)]
82pub struct SqliteBatchInsert;
83
84#[derive(Debug, Copy, Clone)]
85pub struct SqliteReturningClause;
86
87impl sql_dialect::returning_clause::SupportsReturningClause for SqliteReturningClause {}