1 //! The SQLite backend
2 use byteorder::NativeEndian;
3 
4 use super::connection::SqliteValue;
5 use super::query_builder::SqliteQueryBuilder;
6 use backend::*;
7 use query_builder::bind_collector::RawBytesBindCollector;
8 use sql_types::TypeMetadata;
9 
10 /// The SQLite backend
11 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
12 pub struct Sqlite;
13 
14 /// Determines how a bind parameter is given to SQLite
15 ///
16 /// Diesel deals with bind parameters after serialization as opaque blobs of
17 /// bytes. However, SQLite instead has several functions where it expects the
18 /// relevant C types.
19 ///
20 /// The variants of this struct determine what bytes are expected from
21 /// `ToSql` impls.
22 #[allow(missing_debug_implementations)]
23 #[derive(Hash, PartialEq, Eq, Clone, Copy)]
24 pub enum SqliteType {
25     /// Bind using `sqlite3_bind_blob`
26     Binary,
27     /// Bind using `sqlite3_bind_text`
28     Text,
29     /// `bytes` should contain an `f32`
30     Float,
31     /// `bytes` should contain an `f64`
32     Double,
33     /// `bytes` should contain an `i16`
34     SmallInt,
35     /// `bytes` should contain an `i32`
36     Integer,
37     /// `bytes` should contain an `i64`
38     Long,
39 }
40 
41 impl Backend for Sqlite {
42     type QueryBuilder = SqliteQueryBuilder;
43     type BindCollector = RawBytesBindCollector<Sqlite>;
44     type RawValue = SqliteValue;
45     type ByteOrder = NativeEndian;
46 }
47 
48 impl TypeMetadata for Sqlite {
49     type TypeMetadata = SqliteType;
50     type MetadataLookup = ();
51 }
52 
53 impl UsesAnsiSavepointSyntax for Sqlite {}
54