@@ -51,6 +51,7 @@ static TIMESTAMPARRAYOID: Oid = 1115;
5151static TIMESTAMPZOID : Oid = 1184 ;
5252static TIMESTAMPZARRAYOID : Oid = 1185 ;
5353static UUIDOID : Oid = 2950 ;
54+ static UUIDARRAYOID : Oid = 2951 ;
5455static INT4RANGEOID : Oid = 3904 ;
5556static TSRANGEOID : Oid = 3908 ;
5657static TSTZRANGEOID : Oid = 3910 ;
@@ -183,6 +184,8 @@ make_postgres_type!(
183184 VARCHAROID => PgVarchar ,
184185 #[ doc="UUID" ]
185186 UUIDOID => PgUuid ,
187+ #[ doc="UUID[]" ]
188+ UUIDARRAYOID => PgUuidArray member PgUuid ,
186189 #[ doc="INT4RANGE" ]
187190 INT4RANGEOID => PgInt4Range ,
188191 #[ doc="INT8RANGE" ]
@@ -276,6 +279,12 @@ impl RawFromSql for Timespec {
276279 }
277280}
278281
282+ impl RawFromSql for Uuid {
283+ fn raw_from_sql<R : Reader >( len: uint, raw: & mut R ) -> Uuid {
284+ Uuid :: from_bytes( raw. read_bytes( len) ) . unwrap( )
285+ }
286+ }
287+
279288macro_rules! from_map_impl(
280289 ( $( $expected: pat) |+, $t: ty, $blk: expr) => (
281290 impl FromSql for Option <$t> {
@@ -313,15 +322,12 @@ from_raw_from_impl!(PgInt4, i32)
313322from_raw_from_impl!( PgInt8 , i64 )
314323from_raw_from_impl!( PgFloat4 , f32 )
315324from_raw_from_impl!( PgFloat8 , f64 )
325+ from_raw_from_impl!( PgUuid , Uuid )
316326
317327from_map_impl!( PgJson , Json , |buf| {
318328 json:: from_str( str :: from_utf8( buf. as_slice( ) ) ) . unwrap( )
319329} )
320330
321- from_map_impl!( PgUuid , Uuid , |buf| {
322- Uuid :: from_bytes( buf. as_slice( ) ) . unwrap( )
323- } )
324-
325331from_raw_from_impl!( PgTimestamp | PgTimestampTZ , Timespec )
326332
327333macro_rules! from_range_impl(
@@ -412,6 +418,7 @@ from_array_impl!(PgInt8Array, i64)
412418from_array_impl!( PgTimestampArray | PgTimestampTZArray , Timespec )
413419from_array_impl!( PgFloat4Array , f32 )
414420from_array_impl!( PgFloat8Array , f64 )
421+ from_array_impl!( PgUuidArray , Uuid )
415422
416423from_map_impl!( PgUnknownType { name: ~"hstore", .. },
417424 HashMap<~str, Option<~str>>, |buf| {
@@ -518,6 +525,16 @@ impl RawToSql for Timespec {
518525 }
519526}
520527
528+ impl RawToSql for Uuid {
529+ fn raw_to_sql<W: Writer>(&self, w: &mut W) {
530+ w.write(self.to_bytes())
531+ }
532+
533+ fn raw_size(&self) -> uint {
534+ self.to_bytes().len()
535+ }
536+ }
537+
521538macro_rules! to_option_impl(
522539 ($($oid:pat)|+, $t:ty) => (
523540 impl ToSql for Option<$t> {
@@ -601,16 +618,8 @@ impl ToSql for Json {
601618
602619to_option_impl!(PgJson, Json)
603620
604- impl ToSql for Uuid {
605- fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
606- check_types!(PgUuid, ty)
607- (Binary, Some(self.to_bytes().to_owned()))
608- }
609- }
610-
611- to_option_impl!(PgUuid, Uuid)
612-
613621to_raw_to_impl!(PgTimestamp | PgTimestampTZ, Timespec)
622+ to_raw_to_impl!(PgUuid, Uuid)
614623
615624macro_rules! to_range_impl(
616625 ($($oid:ident)|+, $t:ty) => (
@@ -710,6 +719,7 @@ to_array_impl!(PgInt8Array, i64)
710719to_array_impl!(PgTimestampArray | PgTimestampTZArray, Timespec)
711720to_array_impl!(PgFloat4Array, f32)
712721to_array_impl!(PgFloat8Array, f64)
722+ to_array_impl!(PgUuidArray, Uuid)
713723
714724impl<'self> ToSql for HashMap<~str, Option<~str>> {
715725 fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
0 commit comments