@@ -200,9 +200,9 @@ pub mod postgres {
200
200
use super :: { Channel , ChannelSpec } ;
201
201
use bytes:: BytesMut ;
202
202
use hex:: FromHex ;
203
- use postgres_types:: { FromSql , IsNull , ToSql , Type } ;
203
+ use postgres_types:: { accepts , to_sql_checked , FromSql , IsNull , Json , ToSql , Type } ;
204
204
use std:: error:: Error ;
205
- use tokio_postgres:: { types :: Json , Row } ;
205
+ use tokio_postgres:: Row ;
206
206
207
207
impl From < & Row > for Channel {
208
208
fn from ( row : & Row ) -> Self {
@@ -224,12 +224,7 @@ pub mod postgres {
224
224
Ok ( ChannelId :: from_hex ( & str_slice[ 2 ..] ) ?)
225
225
}
226
226
227
- fn accepts ( ty : & Type ) -> bool {
228
- match * ty {
229
- Type :: TEXT | Type :: VARCHAR => true ,
230
- _ => false ,
231
- }
232
- }
227
+ accepts ! ( TEXT , VARCHAR ) ;
233
228
}
234
229
235
230
impl ToSql for ChannelId {
@@ -247,14 +242,19 @@ pub mod postgres {
247
242
<String as ToSql >:: accepts ( ty)
248
243
}
249
244
250
- fn to_sql_checked (
245
+ to_sql_checked ! ( ) ;
246
+ }
247
+
248
+ impl ToSql for ChannelSpec {
249
+ fn to_sql (
251
250
& self ,
252
251
ty : & Type ,
253
- out : & mut BytesMut ,
252
+ w : & mut BytesMut ,
254
253
) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
255
- let string = format ! ( "0x{}" , hex:: encode( self ) ) ;
256
-
257
- <String as ToSql >:: to_sql_checked ( & string, ty, out)
254
+ Json ( self ) . to_sql ( ty, w)
258
255
}
256
+
257
+ accepts ! ( JSONB ) ;
258
+ to_sql_checked ! ( ) ;
259
259
}
260
260
}
0 commit comments