Skip to main content

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 BatchUpdateSupport = SqliteBatchUpdate;
65
66    type EmptyFromClauseSyntax = sql_dialect::from_clause_syntax::AnsiSqlFromClauseSyntax;
67    type SelectStatementSyntax = sql_dialect::select_statement_syntax::AnsiSqlSelectStatement;
68
69    type ExistsSyntax = sql_dialect::exists_syntax::AnsiSqlExistsSyntax;
70    type ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison;
71    type AliasSyntax = sql_dialect::alias_syntax::AsAliasSyntax;
72
73    type WindowFrameClauseGroupSupport =
74        sql_dialect::window_frame_clause_group_support::IsoGroupWindowFrameUnit;
75    type WindowFrameExclusionSupport =
76        sql_dialect::window_frame_exclusion_support::FrameExclusionSupport;
77    type AggregateFunctionExpressions =
78        sql_dialect::aggregate_function_expressions::PostgresLikeAggregateFunctionExpressions;
79    type BuiltInWindowFunctionRequireOrder =
80        sql_dialect::built_in_window_function_require_order::NoOrderRequired;
81
82    type SqlFunctionParameterNotation =
83        sql_dialect::sql_function_parameter_notation::PositionalNotationOnly;
84}
85
86impl DieselReserveSpecialization for Sqlite {}
87impl TrustedBackend for Sqlite {}
88
89#[derive(Debug, Copy, Clone)]
90pub struct SqliteOnConflictClause;
91
92impl sql_dialect::on_conflict_clause::SupportsOnConflictClause for SqliteOnConflictClause {}
93impl sql_dialect::on_conflict_clause::SupportsOnConflictClauseWhere for SqliteOnConflictClause {}
94impl sql_dialect::on_conflict_clause::PgLikeOnConflictClause for SqliteOnConflictClause {}
95
96#[derive(Debug, Copy, Clone)]
97pub struct SqliteBatchInsert;
98
99#[derive(Debug, Copy, Clone)]
100pub struct SqliteReturningClause;
101
102impl sql_dialect::returning_clause::SupportsReturningClause for SqliteReturningClause {}
103
104#[derive(Debug, Clone, Copy)]
105pub struct SqliteBatchUpdate;
106
107impl sql_dialect::batch_update_support::SupportsBatchUpdate for SqliteBatchUpdate {}