| 1 |
//! The SQLite backend |
| 2 |
|
| 3 |
use super::connection::{SqliteBindCollector, SqliteValue}; |
| 4 |
use super::query_builder::SqliteQueryBuilder; |
| 5 |
use crate::backend::*; |
| 6 |
use crate::sql_types::TypeMetadata; |
| 7 |
|
| 8 |
/// The SQLite backend |
| 9 |
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)] |
| 10 |
pub 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)] |
| 22 |
pub 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 |
|
| 39 |
impl Backend for Sqlite { |
| 40 |
type QueryBuilder = SqliteQueryBuilder; |
| 41 |
type RawValue<'a> = SqliteValue<'a, 'a, 'a>; |
| 42 |
type BindCollector<'a> = SqliteBindCollector<'a>; |
| 43 |
} |
| 44 |
|
| 45 |
impl TypeMetadata for Sqlite { |
| 46 |
type TypeMetadata = SqliteType; |
| 47 |
type MetadataLookup = (); |
| 48 |
} |
| 49 |
|
| 50 |
impl 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 |
type WindowFrameClauseGroupSupport = |
| 72 |
sql_dialect::window_frame_clause_group_support::IsoGroupWindowFrameUnit; |
| 73 |
type WindowFrameExclusionSupport = |
| 74 |
sql_dialect::window_frame_exclusion_support::FrameExclusionSupport; |
| 75 |
type AggregateFunctionExpressions = |
| 76 |
sql_dialect::aggregate_function_expressions::PostgresLikeAggregateFunctionExpressions; |
| 77 |
type BuiltInWindowFunctionRequireOrder = |
| 78 |
sql_dialect::built_in_window_function_require_order::NoOrderRequired; |
| 79 |
} |
| 80 |
|
| 81 |
impl DieselReserveSpecialization for Sqlite {} |
| 82 |
impl TrustedBackend for Sqlite {} |
| 83 |
|
| 84 |
#[derive(Debug, Copy, Clone)] |
| 85 |
pub struct SqliteOnConflictClause; |
| 86 |
|
| 87 |
impl sql_dialect::on_conflict_clause::SupportsOnConflictClause for SqliteOnConflictClause {} |
| 88 |
impl sql_dialect::on_conflict_clause::SupportsOnConflictClauseWhere for SqliteOnConflictClause {} |
| 89 |
impl sql_dialect::on_conflict_clause::PgLikeOnConflictClause for SqliteOnConflictClause {} |
| 90 |
|
| 91 |
#[derive(Debug, Copy, Clone)] |
| 92 |
pub struct SqliteBatchInsert; |
| 93 |
|
| 94 |
#[derive(Debug, Copy, Clone)] |
| 95 |
pub struct SqliteReturningClause; |
| 96 |
|
| 97 |
impl sql_dialect::returning_clause::SupportsReturningClause for SqliteReturningClause {} |