good_ormning_runtime/
pg.rs

1use std::borrow::Cow;
2#[cfg(feature = "chrono")]
3use chrono::{
4    DateTime,
5    Utc,
6    FixedOffset,
7};
8
9pub trait GoodOrmningCustomAuto<T> {
10    fn to_sql(value: &T) -> i64;
11    fn from_sql(value: i64) -> Result<T, String>;
12}
13
14pub trait GoodOrmningCustomBool<T> {
15    fn to_sql(value: &T) -> bool;
16    fn from_sql(value: bool) -> Result<T, String>;
17}
18
19pub trait GoodOrmningCustomI32<T> {
20    fn to_sql(value: &T) -> i32;
21    fn from_sql(value: i32) -> Result<T, String>;
22}
23
24pub trait GoodOrmningCustomI64<T> {
25    fn to_sql(value: &T) -> i64;
26    fn from_sql(value: i64) -> Result<T, String>;
27}
28
29pub trait GoodOrmningCustomF32<T> {
30    fn to_sql(value: &T) -> f32;
31    fn from_sql(value: f32) -> Result<T, String>;
32}
33
34pub trait GoodOrmningCustomF64<T> {
35    fn to_sql(value: &T) -> f64;
36    fn from_sql(value: f64) -> Result<T, String>;
37}
38
39pub trait GoodOrmningCustomString<T> {
40    fn to_sql(value: &T) -> &str;
41    fn from_sql(value: String) -> Result<T, String>;
42}
43
44pub trait GoodOrmningCustomBytes<T> {
45    fn to_sql<'a>(value: &'a T) -> Cow<'a, [u8]>;
46    fn from_sql(value: Vec<u8>) -> Result<T, String>;
47}
48
49#[cfg(feature = "chrono")]
50pub trait GoodOrmningCustomUtcTime<T> {
51    fn to_sql(value: &T) -> DateTime<Utc>;
52    fn from_sql(value: DateTime<Utc>) -> Result<T, String>;
53}
54
55#[cfg(feature = "chrono")]
56pub trait GoodOrmningCustomFixedOffsetTime<T> {
57    fn to_sql(value: &T) -> DateTime<FixedOffset>;
58    fn from_sql(value: DateTime<FixedOffset>) -> Result<T, String>;
59}