@@ -2,7 +2,7 @@ use std::io::Write;
22use std:: ops:: Add ;
33
44use deserialize:: { self , FromSql } ;
5- use pg:: { Pg , PgValue , StaticSqlType } ;
5+ use pg:: { Pg , PgValue } ;
66use serialize:: { self , IsNull , Output , ToSql } ;
77use sql_types:: { self , Date , Interval , Time , Timestamp , Timestamptz } ;
88
@@ -90,10 +90,7 @@ impl ToSql<sql_types::Timestamp, Pg> for PgTimestamp {
9090
9191impl FromSql < sql_types:: Timestamp , Pg > for PgTimestamp {
9292 fn from_sql ( bytes : Option < PgValue > ) -> deserialize:: Result < Self > {
93- FromSql :: < sql_types:: BigInt , Pg > :: from_sql (
94- bytes. map ( |b| b. with_new_oid ( sql_types:: BigInt :: OID ) ) ,
95- )
96- . map ( PgTimestamp )
93+ FromSql :: < sql_types:: BigInt , Pg > :: from_sql ( bytes) . map ( PgTimestamp )
9794 }
9895}
9996
@@ -105,9 +102,7 @@ impl ToSql<sql_types::Timestamptz, Pg> for PgTimestamp {
105102
106103impl FromSql < sql_types:: Timestamptz , Pg > for PgTimestamp {
107104 fn from_sql ( bytes : Option < PgValue > ) -> deserialize:: Result < Self > {
108- FromSql :: < sql_types:: Timestamp , Pg > :: from_sql (
109- bytes. map ( |b| b. with_new_oid ( sql_types:: Timestamp :: OID ) ) ,
110- )
105+ FromSql :: < sql_types:: Timestamp , Pg > :: from_sql ( bytes)
111106 }
112107}
113108
@@ -119,10 +114,7 @@ impl ToSql<sql_types::Date, Pg> for PgDate {
119114
120115impl FromSql < sql_types:: Date , Pg > for PgDate {
121116 fn from_sql ( bytes : Option < PgValue > ) -> deserialize:: Result < Self > {
122- FromSql :: < sql_types:: Integer , Pg > :: from_sql (
123- bytes. map ( |b| b. with_new_oid ( sql_types:: Integer :: OID ) ) ,
124- )
125- . map ( PgDate )
117+ FromSql :: < sql_types:: Integer , Pg > :: from_sql ( bytes) . map ( PgDate )
126118 }
127119}
128120
@@ -134,10 +126,7 @@ impl ToSql<sql_types::Time, Pg> for PgTime {
134126
135127impl FromSql < sql_types:: Time , Pg > for PgTime {
136128 fn from_sql ( bytes : Option < PgValue > ) -> deserialize:: Result < Self > {
137- FromSql :: < sql_types:: BigInt , Pg > :: from_sql (
138- bytes. map ( |b| b. with_new_oid ( sql_types:: BigInt :: OID ) ) ,
139- )
140- . map ( PgTime )
129+ FromSql :: < sql_types:: BigInt , Pg > :: from_sql ( bytes) . map ( PgTime )
141130 }
142131}
143132
@@ -153,20 +142,10 @@ impl ToSql<sql_types::Interval, Pg> for PgInterval {
153142impl FromSql < sql_types:: Interval , Pg > for PgInterval {
154143 fn from_sql ( value : Option < PgValue > ) -> deserialize:: Result < Self > {
155144 let value = not_none ! ( value) ;
156- let bytes = value. as_bytes ( ) ;
157145 Ok ( PgInterval {
158- microseconds : FromSql :: < sql_types:: BigInt , Pg > :: from_sql ( Some ( PgValue :: new (
159- & bytes[ ..8 ] ,
160- sql_types:: BigInt :: OID ,
161- ) ) ) ?,
162- days : FromSql :: < sql_types:: Integer , Pg > :: from_sql ( Some ( PgValue :: new (
163- & bytes[ 8 ..12 ] ,
164- sql_types:: Integer :: OID ,
165- ) ) ) ?,
166- months : FromSql :: < sql_types:: Integer , Pg > :: from_sql ( Some ( PgValue :: new (
167- & bytes[ 12 ..16 ] ,
168- sql_types:: Integer :: OID ,
169- ) ) ) ?,
146+ microseconds : FromSql :: < sql_types:: BigInt , Pg > :: from_sql ( Some ( value. subslice ( 0 ..8 ) ) ) ?,
147+ days : FromSql :: < sql_types:: Integer , Pg > :: from_sql ( Some ( value. subslice ( 8 ..12 ) ) ) ?,
148+ months : FromSql :: < sql_types:: Integer , Pg > :: from_sql ( Some ( value. subslice ( 12 ..16 ) ) ) ?,
170149 } )
171150 }
172151}
0 commit comments