good_ormning_runtime/
pg.rs

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