|
| 1 | +/*! |
| 2 | +This crate provides integration points for [Jiff](jiff) and [Diesel](diesel). |
| 3 | +
|
| 4 | +Examples can be found in the |
| 5 | +[examples directory of the Jiff repository][examples]. |
| 6 | +
|
| 7 | +# Organization |
| 8 | +
|
| 9 | +This crates defines several types that wrap corresponding types in |
| 10 | +Jiff. Each wrapper type provides implementations of traits found in |
| 11 | +Diesel. For most types, these are the [`diesel::deserialize::Queryable`], |
| 12 | +[`diesel::deserialize::FromSql`] and [`diesel::serialize::ToSql`] traits. |
| 13 | +
|
| 14 | +The intended workflow is to use these wrapper types within your wire types for |
| 15 | +encoding and decoding data from databases such as PostgreSQL. The wrapper types |
| 16 | +own the logic for encoding and decoding the data in database specific formats. |
| 17 | +
|
| 18 | +In order to the minimize the annoyance of wrapper types, the following |
| 19 | +conveniences are afforded: |
| 20 | +
|
| 21 | +* A [`ToDiesel`] trait is provided. Several Jiff types implement this trait. |
| 22 | +The trait provides easy conversion to the corresponding wrapper type in this |
| 23 | +crate. |
| 24 | +* A concrete `to_jiff` method is provided on each wrapper type. For example, |
| 25 | +[`Timestamp::to_jiff`]. This method is the reverse of `ToDiesel`. This converts |
| 26 | +from the wrapper type to the corresponding Jiff type. |
| 27 | +* There are `From` trait implementations from the wrapper type to the |
| 28 | +corresponding Jiff type, and vice versa. |
| 29 | +
|
| 30 | +# Database support |
| 31 | +
|
| 32 | +At present, MySQL, PostgreSQL and SQLite are supported. |
| 33 | +
|
| 34 | +# Future |
| 35 | +
|
| 36 | +This crate exists because there are generally only three ways to implement |
| 37 | +the necessary traits in Diesel: |
| 38 | +
|
| 39 | +1. Make Jiff depend on Diesel, and implement the corresponding traits where |
| 40 | +Jiff's types are defined. |
| 41 | +2. Make Diesel depend on Jiff, and implement the corresponding traits where the |
| 42 | +traits are defined. |
| 43 | +3. Make a crate like this one with types that wrap Jiff's types, and implements |
| 44 | +the corresponding traits for the wrapper types. |
| 45 | +
|
| 46 | +This was done because it seems inappropriate for a "lower level" crate like |
| 47 | +Jiff to depend on Diesel. And while it might be appropriate for Diesel to |
| 48 | +optionally depend on Jiff (like it does for [`chrono`] or [`time`]), at time of |
| 49 | +writing, Jiff is still early in its life. It's totally reasonable to wait for |
| 50 | +it to mature. Plus, the thought of three different datetime integrations is, |
| 51 | +admittedly, tough to stomach. |
| 52 | +
|
| 53 | +In the future, it may be prudent for this crate to be upstreamed into Diesel |
| 54 | +itself. |
| 55 | +
|
| 56 | +[examples]: https://github.com/BurntSushi/jiff/tree/master/examples |
| 57 | +[`chrono`]: https://docs.rs/chrono |
| 58 | +[`time`]: https://docs.rs/time |
| 59 | +*/ |
| 60 | +#![deny(missing_docs)] |
| 61 | + |
| 62 | +pub use self::wrappers::{Date, DateTime, Span, Time, Timestamp, ToDiesel}; |
| 63 | + |
| 64 | +#[cfg(feature = "mysql")] |
| 65 | +mod mysql; |
| 66 | +#[cfg(feature = "postgres")] |
| 67 | +mod postgres; |
| 68 | +#[cfg(feature = "sqlite")] |
| 69 | +mod sqlite; |
| 70 | +mod wrappers; |
0 commit comments