Trait diesel::backend::Backend

source ·
pub trait Backendwhere
    Self: Sized + SqlDialect + HasSqlType<SmallInt> + HasSqlType<Integer> + HasSqlType<BigInt> + HasSqlType<Float> + HasSqlType<Double> + HasSqlType<Text> + HasSqlType<Binary> + HasSqlType<Date> + HasSqlType<Time> + HasSqlType<Timestamp> + for<'a> HasRawValue<'a> + for<'a> HasBindCollector<'a>,
{ type QueryBuilder: QueryBuilder<Self>; }
Expand description

A database backend

This trait represents the concept of a backend (e.g. “MySQL” vs “SQLite”). It is separate from a Connection to that backend. One backend may have multiple concrete connection implementations.

Implementing a custom backend

Implementing a custom backend requires enabling the i-implement-a-third-party-backend-and-opt-into-breaking-changes crate feature to get access to all necessary type and trait implementations.

Implementations of this trait should not assume details about how the connection is implemented. For example, the Pg backend does not assume that libpq is being used. Implementations of this trait can and should care about details of the wire protocol used to communicated with the database.

Implementing support for a new backend is a complex topic and depends on the details how the newly implemented backend may communicate with diesel. As of this we cannot provide concrete examples here and only present a general outline of the required steps. Existing backend implementations provide a good starting point to see how certain things are solve for other backend implementations.

Types implementing Backend should generally be zero sized structs.

To implement the Backend trait you need to:

  • Specify how a query should be build from string parts by providing a QueryBuilder matching your backend
  • Specify the bind value format used by your database connection library by providing a BindCollector matching your backend via HasBindCollector
  • Specify how values are receive from the database by providing a corresponding raw value definition via HasRawValue
  • Control sql dialect specific parts of diesels query dsl implementation by providing a matching SqlDialect implementation
  • Implement TypeMetadata to specify how your backend identifies types
  • Specify support for common datatypes by implementing HasSqlType for the following sql types:

Additionally to the listed required trait bounds you may want to implement DieselReserveSpecialization to opt in existing wild card QueryFragment impls for large parts of the dsl.

Required Associated Types§

The concrete QueryBuilder implementation for this backend.

Implementors§