diesel/backend.rs
1//! Types which represent various database backends
2
3use byteorder::ByteOrder;
4
5use query_builder::bind_collector::BindCollector;
6use query_builder::QueryBuilder;
7use sql_types::{self, HasSqlType};
8
9/// A database backend
10///
11/// This trait represents the concept of a backend (e.g. "MySQL" vs "SQLite").
12/// It is separate from a [`Connection`](../connection/trait.Connection.html)
13/// to that backend.
14/// One backend may have multiple concrete connection implementations.
15///
16/// Implementations of this trait should not assume details about how the
17/// connection is implemented.
18/// For example, the `Pg` backend does not assume that `libpq` is being used.
19/// Implementations of this trait can and should care about details of the wire
20/// protocol used to communicated with the database.
21pub trait Backend
22where
23 Self: Sized,
24 Self: HasSqlType<sql_types::SmallInt>,
25 Self: HasSqlType<sql_types::Integer>,
26 Self: HasSqlType<sql_types::BigInt>,
27 Self: HasSqlType<sql_types::Float>,
28 Self: HasSqlType<sql_types::Double>,
29 Self: HasSqlType<sql_types::VarChar>,
30 Self: HasSqlType<sql_types::Text>,
31 Self: HasSqlType<sql_types::Binary>,
32 Self: HasSqlType<sql_types::Date>,
33 Self: HasSqlType<sql_types::Time>,
34 Self: HasSqlType<sql_types::Timestamp>,
35{
36 /// The concrete `QueryBuilder` implementation for this backend.
37 type QueryBuilder: QueryBuilder<Self>;
38 /// The concrete `BindCollector` implementation for this backend.
39 ///
40 /// Most backends should use [`RawBytesBindCollector`].
41 ///
42 /// [`RawBytesBindCollector`]: ../query_builder/bind_collector/struct.RawBytesBindCollector.html
43 type BindCollector: BindCollector<Self>;
44 /// The raw representation of a database value given to `FromSql`.
45 ///
46 /// Since most backends transmit data as opaque blobs of bytes, this type
47 /// is usually `[u8]`.
48 type RawValue: ?Sized;
49 /// What byte order is used to transmit integers?
50 ///
51 /// This type is only used if `RawValue` is `[u8]`.
52 type ByteOrder: ByteOrder;
53}
54
55/// Does this backend support `RETURNING` clauses?
56pub trait SupportsReturningClause {}
57/// Does this backend support the bare `DEFAULT` keyword?
58pub trait SupportsDefaultKeyword {}
59/// Does this backend use the standard `SAVEPOINT` syntax?
60pub trait UsesAnsiSavepointSyntax {}
61
62#[cfg(feature = "with-deprecated")]
63#[deprecated(since = "1.1.0", note = "use `sql_types::TypeMetadata` instead")]
64pub use sql_types::TypeMetadata;