@@ -11,102 +11,121 @@ use crate::db::{
1111 LimitedString , Model , PrimaryKey , Result , SqlxValueRef , ToDbFieldValue , ToDbValue ,
1212} ;
1313
14+ mod chrono_fields;
1415mod chrono_wrapper;
1516
1617macro_rules! impl_from_sqlite_default {
1718 ( ) => {
1819 #[ cfg( feature = "sqlite" ) ]
19- fn from_sqlite( value: SqliteValueRef <' _>) -> Result <Self > {
20+ fn from_sqlite(
21+ value: crate :: db:: impl_sqlite:: SqliteValueRef <' _>,
22+ ) -> crate :: db:: Result <Self > {
23+ use crate :: db:: SqlxValueRef ;
2024 value. get:: <Self >( )
2125 }
2226 } ;
2327 ( $wrapper_ty: ty) => {
2428 #[ cfg( feature = "sqlite" ) ]
25- fn from_sqlite( value: SqliteValueRef <' _>) -> Result <Self > {
29+ fn from_sqlite(
30+ value: crate :: db:: impl_sqlite:: SqliteValueRef <' _>,
31+ ) -> crate :: db:: Result <Self > {
2632 <$wrapper_ty as FromDbValue >:: from_sqlite( value) . map( |val| val. into( ) )
2733 }
2834 } ;
2935 ( $wrapper_ty: ty, option) => {
3036 #[ cfg( feature = "sqlite" ) ]
31- fn from_sqlite( value: SqliteValueRef <' _>) -> Result <Self > {
37+ fn from_sqlite(
38+ value: crate :: db:: impl_sqlite:: SqliteValueRef <' _>,
39+ ) -> crate :: db:: Result <Self > {
3240 <$wrapper_ty as FromDbValue >:: from_sqlite( value) . map( |val| val. map( |val| val. into( ) ) )
3341 }
3442 } ;
3543}
44+ use impl_from_sqlite_default;
3645
3746macro_rules! impl_from_postgres_default {
3847 ( ) => {
3948 #[ cfg( feature = "postgres" ) ]
40- fn from_postgres( value: PostgresValueRef <' _>) -> Result <Self > {
49+ fn from_postgres(
50+ value: crate :: db:: impl_postgres:: PostgresValueRef <' _>,
51+ ) -> crate :: db:: Result <Self > {
52+ use crate :: db:: SqlxValueRef ;
4153 value. get:: <Self >( )
4254 }
4355 } ;
4456 ( $wrapper_ty: ty) => {
4557 #[ cfg( feature = "postgres" ) ]
46- fn from_postgres( value: PostgresValueRef <' _>) -> Result <Self > {
58+ fn from_postgres(
59+ value: crate :: db:: impl_postgres:: PostgresValueRef <' _>,
60+ ) -> crate :: db:: Result <Self > {
4761 <$wrapper_ty as FromDbValue >:: from_postgres( value) . map( |val| val. into( ) )
4862 }
4963 } ;
5064 ( $wrapper_ty: ty, option) => {
5165 #[ cfg( feature = "postgres" ) ]
52- fn from_postgres( value: PostgresValueRef <' _>) -> Result <Self > {
66+ fn from_postgres(
67+ value: crate :: db:: impl_postgres:: PostgresValueRef <' _>,
68+ ) -> crate :: db:: Result <Self > {
5369 <$wrapper_ty as FromDbValue >:: from_postgres( value) . map( |val| val. map( |val| val. into( ) ) )
5470 }
5571 } ;
5672}
73+ use impl_from_postgres_default;
5774
5875macro_rules! impl_from_mysql_default {
5976 ( ) => {
6077 #[ cfg( feature = "mysql" ) ]
61- fn from_mysql( value: MySqlValueRef <' _>) -> Result <Self > {
78+ fn from_mysql( value: crate :: db:: impl_mysql:: MySqlValueRef <' _>) -> Result <Self > {
79+ use crate :: db:: SqlxValueRef ;
6280 value. get:: <Self >( )
6381 }
6482 } ;
6583 ( $wrapper_ty: ty) => {
6684 #[ cfg( feature = "mysql" ) ]
67- fn from_mysql( value: MySqlValueRef <' _>) -> Result <Self > {
85+ fn from_mysql( value: crate :: db :: impl_mysql :: MySqlValueRef <' _>) -> Result <Self > {
6886 <$wrapper_ty as FromDbValue >:: from_mysql( value) . map( |val| val. into( ) )
6987 }
7088 } ;
7189 ( $wrapper_ty: ty, option) => {
7290 #[ cfg( feature = "mysql" ) ]
73- fn from_mysql( value: MySqlValueRef <' _>) -> Result <Self > {
91+ fn from_mysql( value: crate :: db :: impl_mysql :: MySqlValueRef <' _>) -> Result <Self > {
7492 <$wrapper_ty as FromDbValue >:: from_mysql( value) . map( |val| val. map( |val| val. into( ) ) )
7593 }
7694 } ;
7795}
7896
7997macro_rules! impl_to_db_value_default {
8098 ( $ty: ty) => {
81- impl ToDbValue for $ty {
82- fn to_db_value( & self ) -> DbValue {
99+ impl crate :: db :: ToDbValue for $ty {
100+ fn to_db_value( & self ) -> crate :: db :: DbValue {
83101 self . clone( ) . into( )
84102 }
85103 }
86104
87- impl ToDbValue for Option <$ty> {
88- fn to_db_value( & self ) -> DbValue {
105+ impl crate :: db :: ToDbValue for Option <$ty> {
106+ fn to_db_value( & self ) -> crate :: db :: DbValue {
89107 self . clone( ) . into( )
90108 }
91109 }
92110 } ;
93111
94112 ( $ty: ty, $wrapper_ty: ty) => {
95- impl ToDbValue for $ty {
96- fn to_db_value( & self ) -> DbValue {
113+ impl crate :: db :: ToDbValue for $ty {
114+ fn to_db_value( & self ) -> crate :: db :: DbValue {
97115 Into :: <$wrapper_ty>:: into( self . clone( ) ) . to_db_value( )
98116 }
99117 }
100118
101- impl ToDbValue for Option <$ty> {
102- fn to_db_value( & self ) -> DbValue {
119+ impl crate :: db :: ToDbValue for Option <$ty> {
120+ fn to_db_value( & self ) -> crate :: db :: DbValue {
103121 self . clone( )
104122 . map( |val| Into :: <$wrapper_ty>:: into( val) )
105123 . to_db_value( )
106124 }
107125 }
108126 } ;
109127}
128+ use impl_to_db_value_default;
110129
111130macro_rules! impl_db_field {
112131 ( $ty: ty, $column_type: ident) => {
@@ -231,35 +250,6 @@ impl ToDbValue for &str {
231250 }
232251}
233252
234- impl DatabaseField for chrono:: DateTime < chrono:: FixedOffset > {
235- const TYPE : ColumnType = ColumnType :: DateTimeWithTimeZone ;
236- }
237-
238- impl FromDbValue for chrono:: DateTime < chrono:: FixedOffset > {
239- impl_from_sqlite_default ! ( ) ;
240-
241- impl_from_postgres_default ! ( ) ;
242-
243- #[ cfg( feature = "mysql" ) ]
244- fn from_mysql ( value : MySqlValueRef < ' _ > ) -> Result < Self > {
245- Ok ( value. get :: < chrono:: DateTime < chrono:: Utc > > ( ) ?. fixed_offset ( ) )
246- }
247- }
248- impl FromDbValue for Option < chrono:: DateTime < chrono:: FixedOffset > > {
249- impl_from_sqlite_default ! ( ) ;
250-
251- impl_from_postgres_default ! ( ) ;
252-
253- #[ cfg( feature = "mysql" ) ]
254- fn from_mysql ( value : MySqlValueRef < ' _ > ) -> Result < Self > {
255- Ok ( value
256- . get :: < Option < chrono:: DateTime < chrono:: Utc > > > ( ) ?
257- . map ( |dt| dt. fixed_offset ( ) ) )
258- }
259- }
260-
261- impl_to_db_value_default ! ( chrono:: DateTime <chrono:: FixedOffset >) ;
262-
263253impl ToDbValue for Option < & str > {
264254 fn to_db_value ( & self ) -> DbValue {
265255 self . map ( ToString :: to_string) . into ( )
0 commit comments