2013-10-20 21:34:50 +00:00
|
|
|
//! Traits dealing with Postgres data types
|
|
|
|
|
2013-09-02 20:54:02 +00:00
|
|
|
extern mod extra;
|
|
|
|
|
2013-09-08 20:27:15 +00:00
|
|
|
use extra::time::Timespec;
|
2013-09-02 20:54:02 +00:00
|
|
|
use extra::json;
|
|
|
|
use extra::json::Json;
|
|
|
|
use extra::uuid::Uuid;
|
2013-12-05 05:20:48 +00:00
|
|
|
use std::hashmap::HashMap;
|
2013-11-13 05:33:52 +00:00
|
|
|
use std::io::Decorator;
|
|
|
|
use std::io::mem::{MemWriter, BufReader};
|
2013-12-04 06:32:54 +00:00
|
|
|
use std::mem;
|
2013-08-28 04:36:27 +00:00
|
|
|
use std::str;
|
2013-12-02 05:09:31 +00:00
|
|
|
use std::vec;
|
2013-08-28 04:36:27 +00:00
|
|
|
|
2013-12-02 05:09:31 +00:00
|
|
|
use self::array::{Array, ArrayBase, DimensionInfo};
|
2013-10-31 06:19:24 +00:00
|
|
|
use self::range::{RangeBound, Inclusive, Exclusive, Range};
|
2013-10-29 06:55:11 +00:00
|
|
|
|
2013-12-02 05:09:31 +00:00
|
|
|
pub mod array;
|
2013-10-29 05:35:52 +00:00
|
|
|
pub mod range;
|
|
|
|
|
2013-09-30 02:47:30 +00:00
|
|
|
/// A Postgres OID
|
2013-08-30 05:58:26 +00:00
|
|
|
pub type Oid = i32;
|
|
|
|
|
2013-08-30 06:28:46 +00:00
|
|
|
// Values from pg_type.h
|
|
|
|
static BOOLOID: Oid = 16;
|
2013-09-02 19:42:24 +00:00
|
|
|
static BYTEAOID: Oid = 17;
|
2013-09-02 22:14:22 +00:00
|
|
|
static CHAROID: Oid = 18;
|
2013-08-31 23:11:42 +00:00
|
|
|
static INT8OID: Oid = 20;
|
|
|
|
static INT2OID: Oid = 21;
|
|
|
|
static INT4OID: Oid = 23;
|
2013-09-02 20:07:57 +00:00
|
|
|
static TEXTOID: Oid = 25;
|
2013-09-02 20:54:02 +00:00
|
|
|
static JSONOID: Oid = 114;
|
2013-08-31 23:11:42 +00:00
|
|
|
static FLOAT4OID: Oid = 700;
|
|
|
|
static FLOAT8OID: Oid = 701;
|
2013-12-07 23:39:44 +00:00
|
|
|
static BOOLARRAYOID: Oid = 1000;
|
|
|
|
static BYTEAARRAYOID: Oid = 1001;
|
2013-12-08 02:49:55 +00:00
|
|
|
static CHARARRAYOID: Oid = 1002;
|
2013-12-08 02:58:40 +00:00
|
|
|
static INT2ARRAYOID: Oid = 1005;
|
2013-12-02 05:09:31 +00:00
|
|
|
static INT4ARRAYOID: Oid = 1007;
|
2013-12-04 06:32:54 +00:00
|
|
|
static INT8ARRAYOID: Oid = 1016;
|
2013-12-06 05:51:09 +00:00
|
|
|
static FLOAT4ARRAYOID: Oid = 1021;
|
2013-12-06 05:58:22 +00:00
|
|
|
static FLAOT8ARRAYOID: Oid = 1022;
|
2013-09-02 21:52:23 +00:00
|
|
|
static BPCHAROID: Oid = 1042;
|
2013-09-02 17:27:09 +00:00
|
|
|
static VARCHAROID: Oid = 1043;
|
2013-09-09 04:33:41 +00:00
|
|
|
static TIMESTAMPOID: Oid = 1114;
|
|
|
|
static TIMESTAMPZOID: Oid = 1184;
|
2013-09-02 20:54:02 +00:00
|
|
|
static UUIDOID: Oid = 2950;
|
2013-10-29 06:55:11 +00:00
|
|
|
static INT4RANGEOID: Oid = 3904;
|
2013-10-31 02:55:25 +00:00
|
|
|
static TSRANGEOID: Oid = 3908;
|
|
|
|
static TSTZRANGEOID: Oid = 3910;
|
2013-10-29 06:55:11 +00:00
|
|
|
static INT8RANGEOID: Oid = 3926;
|
2013-08-30 06:28:46 +00:00
|
|
|
|
2013-09-08 20:27:15 +00:00
|
|
|
static USEC_PER_SEC: i64 = 1_000_000;
|
|
|
|
static NSEC_PER_USEC: i64 = 1_000;
|
|
|
|
|
|
|
|
// Number of seconds from 1970-01-01 to 2000-01-01
|
|
|
|
static TIME_SEC_CONVERSION: i64 = 946684800;
|
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
static RANGE_UPPER_UNBOUNDED: i8 = 0b0001_0000;
|
|
|
|
static RANGE_LOWER_UNBOUNDED: i8 = 0b0000_1000;
|
|
|
|
static RANGE_UPPER_INCLUSIVE: i8 = 0b0000_0100;
|
|
|
|
static RANGE_LOWER_INCLUSIVE: i8 = 0b0000_0010;
|
2013-10-31 07:04:45 +00:00
|
|
|
static RANGE_EMPTY: i8 = 0b0000_0001;
|
2013-10-29 06:55:11 +00:00
|
|
|
|
2013-09-30 02:47:30 +00:00
|
|
|
/// A Postgres type
|
2013-09-05 04:51:21 +00:00
|
|
|
#[deriving(Eq)]
|
2013-09-05 04:26:43 +00:00
|
|
|
pub enum PostgresType {
|
2013-09-30 02:47:30 +00:00
|
|
|
/// BOOL
|
2013-09-05 04:26:43 +00:00
|
|
|
PgBool,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// BYTEA
|
2013-09-05 04:26:43 +00:00
|
|
|
PgByteA,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// "char"
|
2013-09-05 04:26:43 +00:00
|
|
|
PgChar,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// INT8/BIGINT
|
2013-09-05 04:26:43 +00:00
|
|
|
PgInt8,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// INT2/SMALLINT
|
2013-09-05 04:26:43 +00:00
|
|
|
PgInt2,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// INT4/INT
|
2013-09-05 04:26:43 +00:00
|
|
|
PgInt4,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// TEXT
|
2013-09-05 04:26:43 +00:00
|
|
|
PgText,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// JSON
|
2013-09-05 04:26:43 +00:00
|
|
|
PgJson,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// FLOAT4/REAL
|
2013-09-05 04:26:43 +00:00
|
|
|
PgFloat4,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// FLOAT8/DOUBLE PRECISION
|
2013-09-05 04:26:43 +00:00
|
|
|
PgFloat8,
|
2013-12-07 23:39:44 +00:00
|
|
|
/// BOOL[]
|
|
|
|
PgBoolArray,
|
2013-12-08 02:38:53 +00:00
|
|
|
/// BYTEA[]
|
|
|
|
PgByteAArray,
|
2013-12-08 02:49:55 +00:00
|
|
|
/// "char"[]
|
|
|
|
PgCharArray,
|
2013-12-08 02:58:40 +00:00
|
|
|
/// INT2[]
|
|
|
|
PgInt2Array,
|
2013-12-02 05:09:31 +00:00
|
|
|
/// INT4[]
|
|
|
|
PgInt4Array,
|
2013-12-04 06:32:54 +00:00
|
|
|
/// INT8[]
|
|
|
|
PgInt8Array,
|
2013-12-06 05:51:09 +00:00
|
|
|
/// FLOAT4[]
|
|
|
|
PgFloat4Array,
|
2013-12-06 05:58:22 +00:00
|
|
|
/// FLOAT8[]
|
|
|
|
PgFloat8Array,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// TIMESTAMP
|
2013-09-08 20:27:15 +00:00
|
|
|
PgTimestamp,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// TIMESTAMP WITH TIME ZONE
|
2013-09-09 04:33:41 +00:00
|
|
|
PgTimestampZ,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// CHAR(n)/CHARACTER(n)
|
2013-09-05 04:26:43 +00:00
|
|
|
PgCharN,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// VARCHAR/CHARACTER VARYING
|
2013-09-05 04:26:43 +00:00
|
|
|
PgVarchar,
|
2013-09-30 02:47:30 +00:00
|
|
|
/// UUID
|
2013-09-05 04:26:43 +00:00
|
|
|
PgUuid,
|
2013-10-29 06:55:11 +00:00
|
|
|
/// INT4RANGE
|
|
|
|
PgInt4Range,
|
|
|
|
/// INT8RANGE
|
|
|
|
PgInt8Range,
|
2013-10-31 02:55:25 +00:00
|
|
|
/// TSRANGE
|
|
|
|
PgTsRange,
|
|
|
|
/// TSTZRANGE
|
|
|
|
PgTstzRange,
|
2013-12-04 08:18:28 +00:00
|
|
|
/// An unknown type
|
|
|
|
PgUnknownType {
|
|
|
|
/// The name of the type
|
|
|
|
name: ~str,
|
|
|
|
/// The OID of the type
|
|
|
|
oid: Oid
|
|
|
|
}
|
2013-08-30 05:58:26 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
impl PostgresType {
|
2013-12-04 08:18:28 +00:00
|
|
|
#[doc(hidden)]
|
2013-09-05 04:26:43 +00:00
|
|
|
pub fn from_oid(oid: Oid) -> PostgresType {
|
|
|
|
match oid {
|
|
|
|
BOOLOID => PgBool,
|
|
|
|
BYTEAOID => PgByteA,
|
|
|
|
CHAROID => PgChar,
|
|
|
|
INT8OID => PgInt8,
|
|
|
|
INT2OID => PgInt2,
|
|
|
|
INT4OID => PgInt4,
|
|
|
|
TEXTOID => PgText,
|
|
|
|
JSONOID => PgJson,
|
|
|
|
FLOAT4OID => PgFloat4,
|
|
|
|
FLOAT8OID => PgFloat8,
|
2013-12-07 23:39:44 +00:00
|
|
|
BOOLARRAYOID => PgBoolArray,
|
2013-12-08 02:38:53 +00:00
|
|
|
BYTEAARRAYOID => PgByteAArray,
|
2013-12-08 02:49:55 +00:00
|
|
|
CHARARRAYOID => PgCharArray,
|
2013-12-08 02:58:40 +00:00
|
|
|
INT2ARRAYOID => PgInt2Array,
|
2013-12-02 05:09:31 +00:00
|
|
|
INT4ARRAYOID => PgInt4Array,
|
2013-12-04 06:32:54 +00:00
|
|
|
INT8ARRAYOID => PgInt8Array,
|
2013-12-06 05:51:09 +00:00
|
|
|
FLOAT4ARRAYOID => PgFloat4Array,
|
2013-12-06 05:58:22 +00:00
|
|
|
FLAOT8ARRAYOID => PgFloat8Array,
|
2013-09-08 20:27:15 +00:00
|
|
|
TIMESTAMPOID => PgTimestamp,
|
2013-09-09 04:33:41 +00:00
|
|
|
TIMESTAMPZOID => PgTimestampZ,
|
2013-09-05 04:26:43 +00:00
|
|
|
BPCHAROID => PgCharN,
|
|
|
|
VARCHAROID => PgVarchar,
|
|
|
|
UUIDOID => PgUuid,
|
2013-10-29 06:55:11 +00:00
|
|
|
INT4RANGEOID => PgInt4Range,
|
|
|
|
INT8RANGEOID => PgInt8Range,
|
2013-10-31 02:55:25 +00:00
|
|
|
TSRANGEOID => PgTsRange,
|
|
|
|
TSTZRANGEOID => PgTstzRange,
|
2013-12-04 08:18:28 +00:00
|
|
|
// We have to load an empty string now, it'll get filled in later
|
|
|
|
oid => PgUnknownType { name: ~"", oid: oid }
|
2013-09-05 04:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 02:47:30 +00:00
|
|
|
/// Returns the wire format needed for the value of `self`.
|
2013-09-05 04:26:43 +00:00
|
|
|
pub fn result_format(&self) -> Format {
|
|
|
|
match *self {
|
2013-12-05 05:20:48 +00:00
|
|
|
PgUnknownType { name: ~"hstore", .. } => Binary,
|
2013-12-04 08:18:28 +00:00
|
|
|
PgUnknownType { .. } => Text,
|
2013-09-16 02:43:46 +00:00
|
|
|
_ => Binary
|
2013-09-05 04:26:43 +00:00
|
|
|
}
|
2013-09-02 19:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 02:47:30 +00:00
|
|
|
/// The wire format of a Postgres value
|
2013-09-05 04:26:43 +00:00
|
|
|
pub enum Format {
|
2013-10-04 05:13:58 +00:00
|
|
|
/// A user-readable string format
|
2013-09-05 04:26:43 +00:00
|
|
|
Text = 0,
|
2013-10-04 05:13:58 +00:00
|
|
|
/// A machine-readable binary format
|
2013-09-05 04:26:43 +00:00
|
|
|
Binary = 1
|
|
|
|
}
|
|
|
|
|
2013-09-05 04:30:20 +00:00
|
|
|
macro_rules! check_types(
|
|
|
|
($($expected:pat)|+, $actual:ident) => (
|
2013-09-02 20:07:57 +00:00
|
|
|
match $actual {
|
2013-12-04 08:18:28 +00:00
|
|
|
$(&$expected)|+ => (),
|
2013-10-21 04:06:12 +00:00
|
|
|
actual => fail!("Invalid Postgres type {:?}", actual)
|
2013-09-02 19:42:24 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-09-30 05:22:10 +00:00
|
|
|
/// A trait for types that can be created from a Postgres value
|
2013-08-28 04:36:27 +00:00
|
|
|
pub trait FromSql {
|
2013-09-30 02:47:30 +00:00
|
|
|
/// Creates a new value of this type from a buffer of Postgres data.
|
|
|
|
///
|
|
|
|
/// If the value was `NULL`, the buffer will be `None`.
|
|
|
|
///
|
2013-10-13 06:19:57 +00:00
|
|
|
/// # Failure
|
|
|
|
///
|
2013-09-30 02:47:30 +00:00
|
|
|
/// Fails if this type can not be created from the provided Postgres type.
|
2013-12-04 08:18:28 +00:00
|
|
|
fn from_sql(ty: &PostgresType, raw: &Option<~[u8]>) -> Self;
|
2013-08-28 04:36:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
trait RawFromSql {
|
2013-12-08 02:38:53 +00:00
|
|
|
fn raw_from_sql<R: Reader>(len: uint, raw: &mut R) -> Self;
|
2013-10-31 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! raw_from_impl(
|
|
|
|
($t:ty, $f:ident) => (
|
|
|
|
impl RawFromSql for $t {
|
2013-12-08 02:38:53 +00:00
|
|
|
fn raw_from_sql<R: Reader>(_len: uint, raw: &mut R) -> $t {
|
2013-10-31 02:55:25 +00:00
|
|
|
raw.$f()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-07 23:39:44 +00:00
|
|
|
impl RawFromSql for bool {
|
2013-12-08 02:38:53 +00:00
|
|
|
fn raw_from_sql<R: Reader>(_len: uint, raw: &mut R) -> bool {
|
2013-12-07 23:39:44 +00:00
|
|
|
raw.read_u8() != 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-08 02:38:53 +00:00
|
|
|
impl RawFromSql for ~[u8] {
|
|
|
|
fn raw_from_sql<R: Reader>(len: uint, raw: &mut R) -> ~[u8] {
|
|
|
|
raw.read_bytes(len)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-08 02:49:55 +00:00
|
|
|
raw_from_impl!(i8, read_i8)
|
2013-12-08 02:58:40 +00:00
|
|
|
raw_from_impl!(i16, read_be_i16)
|
2013-10-31 02:55:25 +00:00
|
|
|
raw_from_impl!(i32, read_be_i32)
|
|
|
|
raw_from_impl!(i64, read_be_i64)
|
2013-12-06 05:51:09 +00:00
|
|
|
raw_from_impl!(f32, read_be_f32)
|
2013-12-06 05:58:22 +00:00
|
|
|
raw_from_impl!(f64, read_be_f64)
|
2013-10-31 02:55:25 +00:00
|
|
|
|
|
|
|
impl RawFromSql for Timespec {
|
2013-12-08 02:38:53 +00:00
|
|
|
fn raw_from_sql<R: Reader>(_len: uint, raw: &mut R) -> Timespec {
|
2013-10-31 02:55:25 +00:00
|
|
|
let t = raw.read_be_i64();
|
|
|
|
let mut sec = t / USEC_PER_SEC + TIME_SEC_CONVERSION;
|
|
|
|
let mut usec = t % USEC_PER_SEC;
|
|
|
|
|
|
|
|
if usec < 0 {
|
|
|
|
sec -= 1;
|
|
|
|
usec = USEC_PER_SEC + usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timespec::new(sec, (usec * NSEC_PER_USEC) as i32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-02 21:06:22 +00:00
|
|
|
macro_rules! from_map_impl(
|
2013-09-05 04:30:20 +00:00
|
|
|
($($expected:pat)|+, $t:ty, $blk:expr) => (
|
2013-08-28 04:36:27 +00:00
|
|
|
impl FromSql for Option<$t> {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn from_sql(ty: &PostgresType, raw: &Option<~[u8]>) -> Option<$t> {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!($($expected)|+, ty)
|
2013-10-11 03:50:39 +00:00
|
|
|
raw.as_ref().map($blk)
|
2013-08-28 04:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-08 03:05:24 +00:00
|
|
|
|
|
|
|
impl FromSql for $t {
|
|
|
|
fn from_sql(ty: &PostgresType, raw: &Option<~[u8]>) -> $t {
|
|
|
|
// FIXME when you can specify Self types properly
|
|
|
|
let ret: Option<$t> = FromSql::from_sql(ty, raw);
|
|
|
|
ret.unwrap()
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 04:36:27 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
macro_rules! from_raw_from_impl(
|
|
|
|
($($expected:pat)|+, $t:ty) => (
|
|
|
|
from_map_impl!($($expected)|+, $t, |buf| {
|
|
|
|
let mut reader = BufReader::new(buf.as_slice());
|
2013-12-08 02:38:53 +00:00
|
|
|
RawFromSql::raw_from_sql(buf.len(), &mut reader)
|
2013-10-31 02:55:25 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-07 23:39:44 +00:00
|
|
|
from_raw_from_impl!(PgBool, bool)
|
2013-12-08 02:38:53 +00:00
|
|
|
from_raw_from_impl!(PgByteA, ~[u8])
|
2013-12-08 02:49:55 +00:00
|
|
|
from_raw_from_impl!(PgChar, i8)
|
2013-12-08 02:58:40 +00:00
|
|
|
from_raw_from_impl!(PgInt2, i16)
|
2013-10-31 02:55:25 +00:00
|
|
|
from_raw_from_impl!(PgInt4, i32)
|
|
|
|
from_raw_from_impl!(PgInt8, i64)
|
2013-12-06 05:51:09 +00:00
|
|
|
from_raw_from_impl!(PgFloat4, f32)
|
2013-12-06 05:58:22 +00:00
|
|
|
from_raw_from_impl!(PgFloat8, f64)
|
2013-10-31 02:55:25 +00:00
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
from_map_impl!(PgVarchar | PgText | PgCharN, ~str, |buf| {
|
2013-12-05 04:05:53 +00:00
|
|
|
str::from_utf8_owned(buf.clone())
|
2013-09-02 21:06:22 +00:00
|
|
|
})
|
2013-08-28 04:36:27 +00:00
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
from_map_impl!(PgJson, Json, |buf| {
|
2013-12-05 04:05:53 +00:00
|
|
|
json::from_str(str::from_utf8(buf.as_slice())).unwrap()
|
2013-09-02 21:06:22 +00:00
|
|
|
})
|
2013-09-02 20:54:02 +00:00
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
from_map_impl!(PgUuid, Uuid, |buf| {
|
2013-09-07 22:45:11 +00:00
|
|
|
Uuid::from_bytes(buf.as_slice()).unwrap()
|
2013-09-02 21:06:22 +00:00
|
|
|
})
|
2013-09-02 20:54:02 +00:00
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
from_raw_from_impl!(PgTimestamp | PgTimestampZ, Timespec)
|
2013-09-08 20:27:15 +00:00
|
|
|
|
2013-10-30 03:18:27 +00:00
|
|
|
macro_rules! from_range_impl(
|
2013-10-31 02:55:25 +00:00
|
|
|
($($oid:ident)|+, $t:ty) => (
|
|
|
|
from_map_impl!($($oid)|+, Range<$t>, |buf| {
|
2013-10-30 03:18:27 +00:00
|
|
|
let mut rdr = BufReader::new(buf.as_slice());
|
|
|
|
let t = rdr.read_i8();
|
|
|
|
|
2013-10-31 07:04:45 +00:00
|
|
|
if t & RANGE_EMPTY != 0 {
|
|
|
|
Range::empty()
|
|
|
|
} else {
|
|
|
|
let lower = match t & RANGE_LOWER_UNBOUNDED {
|
|
|
|
0 => {
|
|
|
|
let type_ = match t & RANGE_LOWER_INCLUSIVE {
|
|
|
|
0 => Exclusive,
|
|
|
|
_ => Inclusive
|
|
|
|
};
|
2013-12-08 02:38:53 +00:00
|
|
|
let len = rdr.read_be_i32() as uint;
|
|
|
|
Some(RangeBound::new(
|
|
|
|
RawFromSql::raw_from_sql(len, &mut rdr), type_))
|
2013-10-31 07:04:45 +00:00
|
|
|
}
|
|
|
|
_ => None
|
|
|
|
};
|
|
|
|
let upper = match t & RANGE_UPPER_UNBOUNDED {
|
|
|
|
0 => {
|
|
|
|
let type_ = match t & RANGE_UPPER_INCLUSIVE {
|
|
|
|
0 => Exclusive,
|
|
|
|
_ => Inclusive
|
|
|
|
};
|
2013-12-08 02:38:53 +00:00
|
|
|
let len = rdr.read_be_i32() as uint;
|
|
|
|
Some(RangeBound::new(
|
|
|
|
RawFromSql::raw_from_sql(len, &mut rdr), type_))
|
2013-10-31 07:04:45 +00:00
|
|
|
}
|
|
|
|
_ => None
|
|
|
|
};
|
2013-10-31 02:55:25 +00:00
|
|
|
|
2013-10-31 07:04:45 +00:00
|
|
|
Range::new(lower, upper)
|
|
|
|
}
|
2013-10-30 03:18:27 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2013-10-29 06:55:11 +00:00
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
from_range_impl!(PgInt4Range, i32)
|
|
|
|
from_range_impl!(PgInt8Range, i64)
|
|
|
|
from_range_impl!(PgTsRange | PgTstzRange, Timespec)
|
|
|
|
|
2013-12-02 05:09:31 +00:00
|
|
|
macro_rules! from_array_impl(
|
|
|
|
($($oid:ident)|+, $t:ty) => (
|
|
|
|
from_map_impl!($($oid)|+, ArrayBase<Option<$t>>, |buf| {
|
|
|
|
let mut rdr = BufReader::new(buf.as_slice());
|
|
|
|
|
|
|
|
let ndim = rdr.read_be_i32() as uint;
|
|
|
|
let _has_null = rdr.read_be_i32() == 1;
|
|
|
|
let _element_type: Oid = rdr.read_be_i32();
|
|
|
|
|
|
|
|
let mut dim_info = vec::with_capacity(ndim);
|
|
|
|
for _ in range(0, ndim) {
|
|
|
|
dim_info.push(DimensionInfo {
|
|
|
|
len: rdr.read_be_i32() as uint,
|
|
|
|
lower_bound: rdr.read_be_i32() as int
|
|
|
|
});
|
|
|
|
}
|
|
|
|
let nele = dim_info.iter().fold(1, |acc, info| acc * info.len);
|
|
|
|
|
|
|
|
let mut elements = vec::with_capacity(nele);
|
|
|
|
for _ in range(0, nele) {
|
|
|
|
let len = rdr.read_be_i32();
|
|
|
|
if len < 0 {
|
|
|
|
elements.push(None);
|
|
|
|
} else {
|
2013-12-08 02:38:53 +00:00
|
|
|
elements.push(Some(RawFromSql::raw_from_sql(len as uint,
|
|
|
|
&mut rdr)));
|
2013-12-02 05:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayBase::from_raw(elements, dim_info)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-07 23:39:44 +00:00
|
|
|
from_array_impl!(PgBoolArray, bool)
|
2013-12-08 02:38:53 +00:00
|
|
|
from_array_impl!(PgByteAArray, ~[u8])
|
2013-12-08 02:49:55 +00:00
|
|
|
from_array_impl!(PgCharArray, i8)
|
2013-12-08 02:58:40 +00:00
|
|
|
from_array_impl!(PgInt2Array, i16)
|
2013-12-02 05:09:31 +00:00
|
|
|
from_array_impl!(PgInt4Array, i32)
|
2013-12-04 06:32:54 +00:00
|
|
|
from_array_impl!(PgInt8Array, i64)
|
2013-12-06 05:51:09 +00:00
|
|
|
from_array_impl!(PgFloat4Array, f32)
|
2013-12-06 05:58:22 +00:00
|
|
|
from_array_impl!(PgFloat8Array, f64)
|
|
|
|
|
2013-12-05 05:20:48 +00:00
|
|
|
from_map_impl!(PgUnknownType { name: ~"hstore", .. },
|
|
|
|
HashMap<~str, Option<~str>>, |buf| {
|
|
|
|
let mut rdr = BufReader::new(buf.as_slice());
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
|
|
|
|
let count = rdr.read_be_i32();
|
|
|
|
|
|
|
|
for _ in range(0, count) {
|
|
|
|
let key_len = rdr.read_be_i32();
|
|
|
|
let key = str::from_utf8_owned(rdr.read_bytes(key_len as uint));
|
|
|
|
|
|
|
|
let val_len = rdr.read_be_i32();
|
|
|
|
let val = if val_len < 0 {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(str::from_utf8_owned(rdr.read_bytes(val_len as uint)))
|
|
|
|
};
|
|
|
|
|
|
|
|
map.insert(key, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
map
|
|
|
|
})
|
|
|
|
|
2013-09-30 02:47:30 +00:00
|
|
|
/// A trait for types that can be converted into Postgres values
|
2013-08-28 04:36:27 +00:00
|
|
|
pub trait ToSql {
|
2013-09-30 02:47:30 +00:00
|
|
|
/// Converts the value of `self` into a format appropriate for the Postgres
|
|
|
|
/// backend.
|
|
|
|
///
|
2013-10-13 06:19:57 +00:00
|
|
|
/// # Failure
|
|
|
|
///
|
2013-09-30 02:47:30 +00:00
|
|
|
/// Fails if this type cannot be converted into the specified Postgres
|
|
|
|
/// type.
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>);
|
2013-08-28 04:36:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
trait RawToSql {
|
|
|
|
fn raw_to_sql<W: Writer>(&self, w: &mut W);
|
2013-12-04 06:32:54 +00:00
|
|
|
|
|
|
|
fn raw_size(&self) -> uint;
|
2013-10-31 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! raw_to_impl(
|
|
|
|
($t:ty, $f:ident) => (
|
|
|
|
impl RawToSql for $t {
|
|
|
|
fn raw_to_sql<W: Writer>(&self, w: &mut W) {
|
|
|
|
w.$f(*self)
|
|
|
|
}
|
2013-12-04 06:32:54 +00:00
|
|
|
|
|
|
|
fn raw_size(&self) -> uint {
|
|
|
|
mem::size_of::<$t>()
|
|
|
|
}
|
2013-10-31 02:55:25 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-07 23:39:44 +00:00
|
|
|
impl RawToSql for bool {
|
|
|
|
fn raw_to_sql<W: Writer>(&self, w: &mut W) {
|
|
|
|
w.write_u8(*self as u8)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn raw_size(&self) -> uint {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-08 02:38:53 +00:00
|
|
|
impl RawToSql for ~[u8] {
|
|
|
|
fn raw_to_sql<W: Writer>(&self, w: &mut W) {
|
|
|
|
w.write(self.as_slice())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn raw_size(&self) -> uint {
|
|
|
|
self.len()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-08 02:49:55 +00:00
|
|
|
raw_to_impl!(i8, write_i8)
|
2013-12-08 02:58:40 +00:00
|
|
|
raw_to_impl!(i16, write_be_i16)
|
2013-10-31 02:55:25 +00:00
|
|
|
raw_to_impl!(i32, write_be_i32)
|
|
|
|
raw_to_impl!(i64, write_be_i64)
|
2013-12-06 05:51:09 +00:00
|
|
|
raw_to_impl!(f32, write_be_f32)
|
2013-12-06 05:58:22 +00:00
|
|
|
raw_to_impl!(f64, write_be_f64)
|
2013-10-31 02:55:25 +00:00
|
|
|
|
|
|
|
impl RawToSql for Timespec {
|
|
|
|
fn raw_to_sql<W: Writer>(&self, w: &mut W) {
|
|
|
|
let t = (self.sec - TIME_SEC_CONVERSION) * USEC_PER_SEC
|
|
|
|
+ self.nsec as i64 / NSEC_PER_USEC;
|
|
|
|
w.write_be_i64(t);
|
|
|
|
}
|
2013-12-04 06:32:54 +00:00
|
|
|
|
|
|
|
fn raw_size(&self) -> uint {
|
2013-12-07 05:32:44 +00:00
|
|
|
mem::size_of::<i64>()
|
2013-12-04 06:32:54 +00:00
|
|
|
}
|
2013-10-31 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 04:36:27 +00:00
|
|
|
macro_rules! to_option_impl(
|
2013-12-05 05:20:48 +00:00
|
|
|
($($oid:pat)|+, $t:ty) => (
|
2013-08-28 04:36:27 +00:00
|
|
|
impl ToSql for Option<$t> {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!($($oid)|+, ty)
|
2013-09-02 17:27:09 +00:00
|
|
|
|
2013-08-30 05:58:26 +00:00
|
|
|
match *self {
|
|
|
|
None => (Text, None),
|
2013-09-02 17:27:09 +00:00
|
|
|
Some(ref val) => val.to_sql(ty)
|
2013-08-28 04:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 05:20:48 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! to_option_impl_self(
|
|
|
|
($($oid:pat)|+, $t:ty) => (
|
2013-09-02 20:54:02 +00:00
|
|
|
impl<'self> ToSql for Option<$t> {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!($($oid)|+, ty)
|
2013-09-02 20:54:02 +00:00
|
|
|
|
|
|
|
match *self {
|
|
|
|
None => (Text, None),
|
|
|
|
Some(ref val) => val.to_sql(ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 04:36:27 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
macro_rules! to_raw_to_impl(
|
|
|
|
($($oid:ident)|+, $t:ty) => (
|
|
|
|
impl ToSql for $t {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-10-31 02:55:25 +00:00
|
|
|
check_types!($($oid)|+, ty)
|
|
|
|
|
|
|
|
let mut writer = MemWriter::new();
|
|
|
|
self.raw_to_sql(&mut writer);
|
|
|
|
(Binary, Some(writer.inner()))
|
|
|
|
}
|
|
|
|
}
|
2013-12-08 03:05:24 +00:00
|
|
|
|
|
|
|
to_option_impl!($($oid)|+, $t)
|
2013-10-31 02:55:25 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-07 23:39:44 +00:00
|
|
|
to_raw_to_impl!(PgBool, bool)
|
2013-12-08 02:38:53 +00:00
|
|
|
to_raw_to_impl!(PgByteA, ~[u8])
|
2013-12-08 02:49:55 +00:00
|
|
|
to_raw_to_impl!(PgChar, i8)
|
2013-12-08 02:58:40 +00:00
|
|
|
to_raw_to_impl!(PgInt2, i16)
|
2013-10-31 02:55:25 +00:00
|
|
|
to_raw_to_impl!(PgInt4, i32)
|
|
|
|
to_raw_to_impl!(PgInt8, i64)
|
2013-12-06 05:51:09 +00:00
|
|
|
to_raw_to_impl!(PgFloat4, f32)
|
2013-12-06 05:58:22 +00:00
|
|
|
to_raw_to_impl!(PgFloat8, f64)
|
2013-10-31 02:55:25 +00:00
|
|
|
|
2013-11-08 06:13:11 +00:00
|
|
|
impl ToSql for ~str {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-11-08 06:13:11 +00:00
|
|
|
check_types!(PgVarchar | PgText | PgCharN, ty)
|
|
|
|
(Text, Some(self.as_bytes().to_owned()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 04:36:27 +00:00
|
|
|
impl<'self> ToSql for &'self str {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!(PgVarchar | PgText | PgCharN, ty)
|
2013-08-30 05:58:26 +00:00
|
|
|
(Text, Some(self.as_bytes().to_owned()))
|
2013-08-28 04:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
to_option_impl!(PgVarchar | PgText | PgCharN, ~str)
|
2013-12-05 05:20:48 +00:00
|
|
|
to_option_impl_self!(PgVarchar | PgText | PgCharN, &'self str)
|
2013-09-02 19:42:24 +00:00
|
|
|
|
|
|
|
impl<'self> ToSql for &'self [u8] {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!(PgByteA, ty)
|
2013-09-02 19:42:24 +00:00
|
|
|
(Binary, Some(self.to_owned()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-05 05:20:48 +00:00
|
|
|
to_option_impl_self!(PgByteA, &'self [u8])
|
2013-09-02 19:42:24 +00:00
|
|
|
|
2013-09-02 20:54:02 +00:00
|
|
|
impl ToSql for Json {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!(PgJson, ty)
|
2013-09-02 20:54:02 +00:00
|
|
|
(Text, Some(self.to_str().into_bytes()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
to_option_impl!(PgJson, Json)
|
2013-09-02 20:54:02 +00:00
|
|
|
|
|
|
|
impl ToSql for Uuid {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-09-05 04:30:20 +00:00
|
|
|
check_types!(PgUuid, ty)
|
2013-09-02 20:54:02 +00:00
|
|
|
(Binary, Some(self.to_bytes().to_owned()))
|
2013-09-02 19:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-02 20:54:02 +00:00
|
|
|
|
2013-09-05 04:26:43 +00:00
|
|
|
to_option_impl!(PgUuid, Uuid)
|
2013-09-08 20:27:15 +00:00
|
|
|
|
2013-10-31 02:55:25 +00:00
|
|
|
to_raw_to_impl!(PgTimestamp | PgTimestampZ, Timespec)
|
2013-10-29 06:55:11 +00:00
|
|
|
|
2013-10-30 03:18:27 +00:00
|
|
|
macro_rules! to_range_impl(
|
2013-12-04 06:32:54 +00:00
|
|
|
($($oid:ident)|+, $t:ty) => (
|
2013-10-31 02:55:25 +00:00
|
|
|
impl ToSql for Range<$t> {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-10-31 02:55:25 +00:00
|
|
|
check_types!($($oid)|+, ty)
|
2013-10-30 03:18:27 +00:00
|
|
|
let mut buf = MemWriter::new();
|
2013-10-31 02:55:25 +00:00
|
|
|
|
|
|
|
let mut tag = 0;
|
2013-10-31 07:04:45 +00:00
|
|
|
if self.is_empty() {
|
|
|
|
tag |= RANGE_EMPTY;
|
|
|
|
} else {
|
2013-12-06 07:09:03 +00:00
|
|
|
match *self.lower() {
|
|
|
|
None => tag |= RANGE_LOWER_UNBOUNDED,
|
|
|
|
Some(RangeBound { type_: Inclusive, .. }) =>
|
2013-10-31 07:04:45 +00:00
|
|
|
tag |= RANGE_LOWER_INCLUSIVE,
|
|
|
|
_ => {}
|
|
|
|
}
|
2013-12-06 07:09:03 +00:00
|
|
|
match *self.upper() {
|
|
|
|
None => tag |= RANGE_UPPER_UNBOUNDED,
|
|
|
|
Some(RangeBound { type_: Inclusive, .. }) =>
|
2013-10-31 07:04:45 +00:00
|
|
|
tag |= RANGE_UPPER_INCLUSIVE,
|
|
|
|
_ => {}
|
|
|
|
}
|
2013-10-31 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf.write_i8(tag);
|
|
|
|
|
2013-12-06 07:09:03 +00:00
|
|
|
match *self.lower() {
|
|
|
|
Some(ref bound) => {
|
2013-12-04 06:32:54 +00:00
|
|
|
buf.write_be_i32(bound.value.raw_size() as i32);
|
2013-10-31 02:55:25 +00:00
|
|
|
bound.value.raw_to_sql(&mut buf);
|
2013-10-30 03:18:27 +00:00
|
|
|
}
|
2013-12-06 07:09:03 +00:00
|
|
|
None => {}
|
2013-10-31 02:55:25 +00:00
|
|
|
}
|
2013-12-06 07:09:03 +00:00
|
|
|
match *self.upper() {
|
|
|
|
Some(ref bound) => {
|
2013-12-04 06:32:54 +00:00
|
|
|
buf.write_be_i32(bound.value.raw_size() as i32);
|
2013-10-31 02:55:25 +00:00
|
|
|
bound.value.raw_to_sql(&mut buf);
|
2013-10-30 03:18:27 +00:00
|
|
|
}
|
2013-12-06 07:09:03 +00:00
|
|
|
None => {}
|
2013-10-30 03:18:27 +00:00
|
|
|
}
|
2013-10-29 06:55:11 +00:00
|
|
|
|
2013-10-30 03:18:27 +00:00
|
|
|
(Binary, Some(buf.inner()))
|
2013-10-29 06:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-08 03:05:24 +00:00
|
|
|
|
|
|
|
to_option_impl!($($oid)|+, Range<$t>)
|
2013-10-30 03:18:27 +00:00
|
|
|
)
|
|
|
|
)
|
2013-10-29 06:55:11 +00:00
|
|
|
|
2013-12-04 06:32:54 +00:00
|
|
|
to_range_impl!(PgInt4Range, i32)
|
|
|
|
to_range_impl!(PgInt8Range, i64)
|
|
|
|
to_range_impl!(PgTsRange | PgTstzRange, Timespec)
|
2013-12-02 05:09:31 +00:00
|
|
|
|
|
|
|
macro_rules! to_array_impl(
|
2013-12-04 06:32:54 +00:00
|
|
|
($($oid:ident)|+, $base_oid:ident, $t:ty) => (
|
2013-12-02 05:09:31 +00:00
|
|
|
impl ToSql for ArrayBase<Option<$t>> {
|
2013-12-04 08:18:28 +00:00
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
2013-12-02 05:09:31 +00:00
|
|
|
check_types!($($oid)|+, ty)
|
|
|
|
let mut buf = MemWriter::new();
|
|
|
|
|
2013-12-03 08:00:28 +00:00
|
|
|
buf.write_be_i32(self.dimension_info().len() as i32);
|
2013-12-02 05:09:31 +00:00
|
|
|
buf.write_be_i32(1);
|
|
|
|
buf.write_be_i32($base_oid);
|
|
|
|
|
2013-12-03 08:00:28 +00:00
|
|
|
for info in self.dimension_info().iter() {
|
2013-12-02 05:09:31 +00:00
|
|
|
buf.write_be_i32(info.len as i32);
|
|
|
|
buf.write_be_i32(info.lower_bound as i32);
|
|
|
|
}
|
|
|
|
|
|
|
|
for v in self.values() {
|
|
|
|
match *v {
|
|
|
|
Some(ref val) => {
|
2013-12-04 06:32:54 +00:00
|
|
|
buf.write_be_i32(val.raw_size() as i32);
|
2013-12-02 05:09:31 +00:00
|
|
|
val.raw_to_sql(&mut buf);
|
|
|
|
}
|
|
|
|
None => buf.write_be_i32(-1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(Binary, Some(buf.inner()))
|
|
|
|
}
|
|
|
|
}
|
2013-12-08 03:05:24 +00:00
|
|
|
|
|
|
|
to_option_impl!($($oid)|+, ArrayBase<Option<$t>>)
|
2013-12-02 05:09:31 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-07 23:39:44 +00:00
|
|
|
to_array_impl!(PgBoolArray, BOOLOID, bool)
|
2013-12-08 02:38:53 +00:00
|
|
|
to_array_impl!(PgByteAArray, BYTEAOID, ~[u8])
|
2013-12-08 02:49:55 +00:00
|
|
|
to_array_impl!(PgCharArray, CHAROID, i8)
|
2013-12-08 02:58:40 +00:00
|
|
|
to_array_impl!(PgInt2Array, INT2OID, i16)
|
2013-12-04 06:32:54 +00:00
|
|
|
to_array_impl!(PgInt4Array, INT4OID, i32)
|
|
|
|
to_array_impl!(PgInt8Array, INT8OID, i64)
|
2013-12-06 05:51:09 +00:00
|
|
|
to_array_impl!(PgFloat4Array, FLOAT4OID, f32)
|
2013-12-06 05:58:22 +00:00
|
|
|
to_array_impl!(PgFloat8Array, FLOAT8OID, f64)
|
|
|
|
|
2013-12-05 05:20:48 +00:00
|
|
|
impl<'self> ToSql for HashMap<~str, Option<~str>> {
|
|
|
|
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
|
|
|
check_types!(PgUnknownType { name: ~"hstore", .. }, ty)
|
|
|
|
let mut buf = MemWriter::new();
|
|
|
|
|
|
|
|
buf.write_be_i32(self.len() as i32);
|
|
|
|
|
|
|
|
for (key, val) in self.iter() {
|
|
|
|
buf.write_be_i32(key.len() as i32);
|
|
|
|
buf.write(key.as_bytes());
|
|
|
|
|
|
|
|
match *val {
|
|
|
|
Some(ref val) => {
|
|
|
|
buf.write_be_i32(val.len() as i32);
|
|
|
|
buf.write(val.as_bytes());
|
|
|
|
}
|
|
|
|
None => buf.write_be_i32(-1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(Binary, Some(buf.inner()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
to_option_impl!(PgUnknownType { name: ~"hstore", .. },
|
|
|
|
HashMap<~str, Option<~str>>)
|