diesel-chrono-duration
This crate adds support for the chrono::Duration
type into the diesel
ORM.
Why
Diesel crate has a policy of including only such type implementations which can be represented as is in the SQL types. chrono::Duration
does not have a direct 1-to-1 mapping in both the SQLite
and PostgreSQL
.
How
The chrono::Duration
type stores its value as i64
number. This is exactly 8 bytes and such types are BigInteger
and BigInt
. So, the ToSql
and FromSql
traits implementation simply uses chrono::Duration
's inner
i64
value.
Usage
To implement this we added ChronoDurationProxy
type which is just a strong type as defined as:
;
In your table model you use it instead of chrono::Duration
:
extern crate diesel_chrono_duration;
use ChronoDurationProxy;
Later, when you want to use it's value as chrono::Duration
you have these options:
*duration
returns a reference to the innerchrono::Duration
object. It is done by theDeref
trait.&duration
also returns a reference to the innerchrono::Duration
object. It is done by theAsRef
trait.duration.0
as in usual rust.
Contribute
The project is very simple and small but all contributions are "please make a contribution". Thanks in advance.
License
This project is licensed under the MIT license.