Remove fixmes in Type builder

This commit is contained in:
Steven Fackler 2016-02-21 19:17:23 -08:00
parent dede1189b4
commit 7d07e61e9c
5 changed files with 52 additions and 99 deletions

View File

@ -71,14 +71,6 @@ fn parse_types(ranges: &BTreeMap<u32, u32>) -> BTreeMap<u32, Type> {
let variant = match name { let variant = match name {
"anyarray" => "AnyArray".to_owned(), "anyarray" => "AnyArray".to_owned(),
// FIXME remove following overrides for 0.12
"anyrange" => "Anyrange".to_owned(),
"tsvector" => "Tsvector".to_owned(),
"gtsvector" => "Gtsvector".to_owned(),
"_tsvector" => "TsvectorArray".to_owned(),
"_gtsvector" => "GtsvectorArray".to_owned(),
"timestamptz" => "TimestampTZ".to_owned(),
"_timestamptz" => "TimestampTZArray".to_owned(),
name => { name => {
let variant = range_vector_re.replace(name, "_$1"); let variant = range_vector_re.replace(name, "_$1");
let variant = array_re.replace(&variant, "$1_array"); let variant = array_re.replace(&variant, "$1_array");
@ -88,13 +80,10 @@ fn parse_types(ranges: &BTreeMap<u32, u32>) -> BTreeMap<u32, Type> {
let kind = split[11]; let kind = split[11];
// FIXME enable for 0.12
/*
// we need to be able to pull composite fields and enum variants at runtime // we need to be able to pull composite fields and enum variants at runtime
if kind == "C" || kind == "E" { if kind == "C" || kind == "E" {
continue; continue;
} }
*/
let element = if let Some(&element) = ranges.get(&oid) { let element = if let Some(&element) = ranges.get(&oid) {
element element

View File

@ -46,7 +46,7 @@ impl FromSql for DateTime<UTC> {
Ok(DateTime::from_utc(naive, UTC)) Ok(DateTime::from_utc(naive, UTC))
} }
accepts!(Type::TimestampTZ); accepts!(Type::Timestamptz);
} }
impl ToSql for DateTime<UTC> { impl ToSql for DateTime<UTC> {
@ -58,7 +58,7 @@ impl ToSql for DateTime<UTC> {
self.naive_utc().to_sql(type_, w, info) self.naive_utc().to_sql(type_, w, info)
} }
accepts!(Type::TimestampTZ); accepts!(Type::Timestamptz);
to_sql_checked!(); to_sql_checked!();
} }
@ -68,7 +68,7 @@ impl FromSql for DateTime<Local> {
Ok(utc.with_timezone(&Local)) Ok(utc.with_timezone(&Local))
} }
accepts!(Type::TimestampTZ); accepts!(Type::Timestamptz);
} }
impl ToSql for DateTime<Local> { impl ToSql for DateTime<Local> {
@ -80,7 +80,7 @@ impl ToSql for DateTime<Local> {
self.with_timezone(&UTC).to_sql(type_, w, info) self.with_timezone(&UTC).to_sql(type_, w, info)
} }
accepts!(Type::TimestampTZ); accepts!(Type::Timestamptz);
to_sql_checked!(); to_sql_checked!();
} }
@ -93,7 +93,7 @@ impl FromSql for DateTime<FixedOffset> {
Ok(utc.with_timezone(&FixedOffset::east(0))) Ok(utc.with_timezone(&FixedOffset::east(0)))
} }
accepts!(Type::TimestampTZ); accepts!(Type::Timestamptz);
} }
impl ToSql for DateTime<FixedOffset> { impl ToSql for DateTime<FixedOffset> {
@ -105,7 +105,7 @@ impl ToSql for DateTime<FixedOffset> {
self.with_timezone(&UTC).to_sql(type_, w, info) self.with_timezone(&UTC).to_sql(type_, w, info)
} }
accepts!(Type::TimestampTZ); accepts!(Type::Timestamptz);
to_sql_checked!(); to_sql_checked!();
} }

View File

@ -61,7 +61,7 @@ impl<T: ToSql> ToSql for Date<T> {
to_sql_checked!(); to_sql_checked!();
} }
/// A wrapper that can be used to represent infinity with `Type::Timestamp` and `Type::TimestampTZ` /// A wrapper that can be used to represent infinity with `Type::Timestamp` and `Type::Timestamptz`
/// types. /// types.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Timestamp<T> { pub enum Timestamp<T> {
@ -75,7 +75,7 @@ pub enum Timestamp<T> {
impl<T: FromSql> FromSql for Timestamp<T> { impl<T: FromSql> FromSql for Timestamp<T> {
fn from_sql<R: Read>(ty: &Type, raw: &mut R, ctx: &SessionInfo) -> Result<Self> { fn from_sql<R: Read>(ty: &Type, raw: &mut R, ctx: &SessionInfo) -> Result<Self> {
if *ty != Type::Timestamp && *ty != Type::TimestampTZ { if *ty != Type::Timestamp && *ty != Type::Timestamptz {
return Err(Error::Conversion("expected timestamp or timestamptz type".into())); return Err(Error::Conversion("expected timestamp or timestamptz type".into()));
} }
@ -90,13 +90,13 @@ impl<T: FromSql> FromSql for Timestamp<T> {
} }
fn accepts(ty: &Type) -> bool { fn accepts(ty: &Type) -> bool {
(*ty == Type::Timestamp || *ty == Type::TimestampTZ) && T::accepts(ty) (*ty == Type::Timestamp || *ty == Type::Timestamptz) && T::accepts(ty)
} }
} }
impl<T: ToSql> ToSql for Timestamp<T> { impl<T: ToSql> ToSql for Timestamp<T> {
fn to_sql<W: Write+?Sized>(&self, ty: &Type, out: &mut W, ctx: &SessionInfo) -> Result<IsNull> { fn to_sql<W: Write+?Sized>(&self, ty: &Type, out: &mut W, ctx: &SessionInfo) -> Result<IsNull> {
if *ty != Type::Timestamp && *ty != Type::TimestampTZ { if *ty != Type::Timestamp && *ty != Type::Timestamptz {
return Err(Error::Conversion("expected timestamp or timestamptz type".into())); return Err(Error::Conversion("expected timestamp or timestamptz type".into()));
} }
@ -111,7 +111,7 @@ impl<T: ToSql> ToSql for Timestamp<T> {
} }
fn accepts(ty: &Type) -> bool { fn accepts(ty: &Type) -> bool {
(*ty == Type::Timestamp || *ty == Type::TimestampTZ) && T::accepts(ty) (*ty == Type::Timestamp || *ty == Type::Timestamptz) && T::accepts(ty)
} }
to_sql_checked!(); to_sql_checked!();

View File

@ -27,7 +27,7 @@ impl FromSql for Timespec {
Ok(Timespec::new(sec, (usec * NSEC_PER_USEC) as i32)) Ok(Timespec::new(sec, (usec * NSEC_PER_USEC) as i32))
} }
accepts!(Type::Timestamp, Type::TimestampTZ); accepts!(Type::Timestamp, Type::Timestamptz);
} }
impl ToSql for Timespec { impl ToSql for Timespec {
@ -41,6 +41,6 @@ impl ToSql for Timespec {
Ok(IsNull::No) Ok(IsNull::No)
} }
accepts!(Type::Timestamp, Type::TimestampTZ); accepts!(Type::Timestamp, Type::Timestamptz);
to_sql_checked!(); to_sql_checked!();
} }

View File

@ -38,14 +38,6 @@ pub enum Type {
OidVector, OidVector,
/// PG_DDL_COMMAND - internal type for passing CollectedCommand /// PG_DDL_COMMAND - internal type for passing CollectedCommand
PgDdlCommand, PgDdlCommand,
/// PG_TYPE
PgType,
/// PG_ATTRIBUTE
PgAttribute,
/// PG_PROC
PgProc,
/// PG_CLASS
PgClass,
/// JSON /// JSON
Json, Json,
/// XML - XML content /// XML - XML content
@ -179,9 +171,9 @@ pub enum Type {
/// TIME&#91;&#93; /// TIME&#91;&#93;
TimeArray, TimeArray,
/// TIMESTAMPTZ - date and time with time zone /// TIMESTAMPTZ - date and time with time zone
TimestampTZ, Timestamptz,
/// TIMESTAMPTZ&#91;&#93; /// TIMESTAMPTZ&#91;&#93;
TimestampTZArray, TimestamptzArray,
/// INTERVAL - &#64; &lt;number&gt; &lt;units&gt;, time interval /// INTERVAL - &#64; &lt;number&gt; &lt;units&gt;, time interval
Interval, Interval,
/// INTERVAL&#91;&#93; /// INTERVAL&#91;&#93;
@ -271,15 +263,15 @@ pub enum Type {
/// ANYENUM /// ANYENUM
Anyenum, Anyenum,
/// TSVECTOR - text representation for text search /// TSVECTOR - text representation for text search
Tsvector, TsVector,
/// TSQUERY - query representation for text search /// TSQUERY - query representation for text search
Tsquery, Tsquery,
/// GTSVECTOR - GiST index internal text representation for text search /// GTSVECTOR - GiST index internal text representation for text search
Gtsvector, GtsVector,
/// TSVECTOR&#91;&#93; /// TSVECTOR&#91;&#93;
TsvectorArray, TsVectorArray,
/// GTSVECTOR&#91;&#93; /// GTSVECTOR&#91;&#93;
GtsvectorArray, GtsVectorArray,
/// TSQUERY&#91;&#93; /// TSQUERY&#91;&#93;
TsqueryArray, TsqueryArray,
/// REGCONFIG - registered text search configuration /// REGCONFIG - registered text search configuration
@ -295,7 +287,7 @@ pub enum Type {
/// JSONB&#91;&#93; /// JSONB&#91;&#93;
JsonbArray, JsonbArray,
/// ANYRANGE /// ANYRANGE
Anyrange, AnyRange,
/// EVENT_TRIGGER /// EVENT_TRIGGER
EventTrigger, EventTrigger,
/// INT4RANGE - range of integers /// INT4RANGE - range of integers
@ -365,10 +357,6 @@ impl Type {
29 => Some(Type::Cid), 29 => Some(Type::Cid),
30 => Some(Type::OidVector), 30 => Some(Type::OidVector),
32 => Some(Type::PgDdlCommand), 32 => Some(Type::PgDdlCommand),
71 => Some(Type::PgType),
75 => Some(Type::PgAttribute),
81 => Some(Type::PgProc),
83 => Some(Type::PgClass),
114 => Some(Type::Json), 114 => Some(Type::Json),
142 => Some(Type::Xml), 142 => Some(Type::Xml),
143 => Some(Type::XmlArray), 143 => Some(Type::XmlArray),
@ -435,8 +423,8 @@ impl Type {
1115 => Some(Type::TimestampArray), 1115 => Some(Type::TimestampArray),
1182 => Some(Type::DateArray), 1182 => Some(Type::DateArray),
1183 => Some(Type::TimeArray), 1183 => Some(Type::TimeArray),
1184 => Some(Type::TimestampTZ), 1184 => Some(Type::Timestamptz),
1185 => Some(Type::TimestampTZArray), 1185 => Some(Type::TimestamptzArray),
1186 => Some(Type::Interval), 1186 => Some(Type::Interval),
1187 => Some(Type::IntervalArray), 1187 => Some(Type::IntervalArray),
1231 => Some(Type::NumericArray), 1231 => Some(Type::NumericArray),
@ -481,11 +469,11 @@ impl Type {
3221 => Some(Type::PgLsnArray), 3221 => Some(Type::PgLsnArray),
3310 => Some(Type::TsmHandler), 3310 => Some(Type::TsmHandler),
3500 => Some(Type::Anyenum), 3500 => Some(Type::Anyenum),
3614 => Some(Type::Tsvector), 3614 => Some(Type::TsVector),
3615 => Some(Type::Tsquery), 3615 => Some(Type::Tsquery),
3642 => Some(Type::Gtsvector), 3642 => Some(Type::GtsVector),
3643 => Some(Type::TsvectorArray), 3643 => Some(Type::TsVectorArray),
3644 => Some(Type::GtsvectorArray), 3644 => Some(Type::GtsVectorArray),
3645 => Some(Type::TsqueryArray), 3645 => Some(Type::TsqueryArray),
3734 => Some(Type::Regconfig), 3734 => Some(Type::Regconfig),
3735 => Some(Type::RegconfigArray), 3735 => Some(Type::RegconfigArray),
@ -493,7 +481,7 @@ impl Type {
3770 => Some(Type::RegdictionaryArray), 3770 => Some(Type::RegdictionaryArray),
3802 => Some(Type::Jsonb), 3802 => Some(Type::Jsonb),
3807 => Some(Type::JsonbArray), 3807 => Some(Type::JsonbArray),
3831 => Some(Type::Anyrange), 3831 => Some(Type::AnyRange),
3838 => Some(Type::EventTrigger), 3838 => Some(Type::EventTrigger),
3904 => Some(Type::Int4Range), 3904 => Some(Type::Int4Range),
3905 => Some(Type::Int4RangeArray), 3905 => Some(Type::Int4RangeArray),
@ -534,10 +522,6 @@ impl Type {
Type::Cid => 29, Type::Cid => 29,
Type::OidVector => 30, Type::OidVector => 30,
Type::PgDdlCommand => 32, Type::PgDdlCommand => 32,
Type::PgType => 71,
Type::PgAttribute => 75,
Type::PgProc => 81,
Type::PgClass => 83,
Type::Json => 114, Type::Json => 114,
Type::Xml => 142, Type::Xml => 142,
Type::XmlArray => 143, Type::XmlArray => 143,
@ -604,8 +588,8 @@ impl Type {
Type::TimestampArray => 1115, Type::TimestampArray => 1115,
Type::DateArray => 1182, Type::DateArray => 1182,
Type::TimeArray => 1183, Type::TimeArray => 1183,
Type::TimestampTZ => 1184, Type::Timestamptz => 1184,
Type::TimestampTZArray => 1185, Type::TimestamptzArray => 1185,
Type::Interval => 1186, Type::Interval => 1186,
Type::IntervalArray => 1187, Type::IntervalArray => 1187,
Type::NumericArray => 1231, Type::NumericArray => 1231,
@ -650,11 +634,11 @@ impl Type {
Type::PgLsnArray => 3221, Type::PgLsnArray => 3221,
Type::TsmHandler => 3310, Type::TsmHandler => 3310,
Type::Anyenum => 3500, Type::Anyenum => 3500,
Type::Tsvector => 3614, Type::TsVector => 3614,
Type::Tsquery => 3615, Type::Tsquery => 3615,
Type::Gtsvector => 3642, Type::GtsVector => 3642,
Type::TsvectorArray => 3643, Type::TsVectorArray => 3643,
Type::GtsvectorArray => 3644, Type::GtsVectorArray => 3644,
Type::TsqueryArray => 3645, Type::TsqueryArray => 3645,
Type::Regconfig => 3734, Type::Regconfig => 3734,
Type::RegconfigArray => 3735, Type::RegconfigArray => 3735,
@ -662,7 +646,7 @@ impl Type {
Type::RegdictionaryArray => 3770, Type::RegdictionaryArray => 3770,
Type::Jsonb => 3802, Type::Jsonb => 3802,
Type::JsonbArray => 3807, Type::JsonbArray => 3807,
Type::Anyrange => 3831, Type::AnyRange => 3831,
Type::EventTrigger => 3838, Type::EventTrigger => 3838,
Type::Int4Range => 3904, Type::Int4Range => 3904,
Type::Int4RangeArray => 3905, Type::Int4RangeArray => 3905,
@ -751,22 +735,6 @@ impl Type {
const V: &'static Kind = &Kind::Pseudo; const V: &'static Kind = &Kind::Pseudo;
V V
} }
Type::PgType => {
const V: &'static Kind = &Kind::Simple;
V
}
Type::PgAttribute => {
const V: &'static Kind = &Kind::Simple;
V
}
Type::PgProc => {
const V: &'static Kind = &Kind::Simple;
V
}
Type::PgClass => {
const V: &'static Kind = &Kind::Simple;
V
}
Type::Json => { Type::Json => {
const V: &'static Kind = &Kind::Simple; const V: &'static Kind = &Kind::Simple;
V V
@ -1031,12 +999,12 @@ impl Type {
const V: &'static Kind = &Kind::Array(Type::Time); const V: &'static Kind = &Kind::Array(Type::Time);
V V
} }
Type::TimestampTZ => { Type::Timestamptz => {
const V: &'static Kind = &Kind::Simple; const V: &'static Kind = &Kind::Simple;
V V
} }
Type::TimestampTZArray => { Type::TimestamptzArray => {
const V: &'static Kind = &Kind::Array(Type::TimestampTZ); const V: &'static Kind = &Kind::Array(Type::Timestamptz);
V V
} }
Type::Interval => { Type::Interval => {
@ -1215,7 +1183,7 @@ impl Type {
const V: &'static Kind = &Kind::Pseudo; const V: &'static Kind = &Kind::Pseudo;
V V
} }
Type::Tsvector => { Type::TsVector => {
const V: &'static Kind = &Kind::Simple; const V: &'static Kind = &Kind::Simple;
V V
} }
@ -1223,16 +1191,16 @@ impl Type {
const V: &'static Kind = &Kind::Simple; const V: &'static Kind = &Kind::Simple;
V V
} }
Type::Gtsvector => { Type::GtsVector => {
const V: &'static Kind = &Kind::Simple; const V: &'static Kind = &Kind::Simple;
V V
} }
Type::TsvectorArray => { Type::TsVectorArray => {
const V: &'static Kind = &Kind::Array(Type::Tsvector); const V: &'static Kind = &Kind::Array(Type::TsVector);
V V
} }
Type::GtsvectorArray => { Type::GtsVectorArray => {
const V: &'static Kind = &Kind::Array(Type::Gtsvector); const V: &'static Kind = &Kind::Array(Type::GtsVector);
V V
} }
Type::TsqueryArray => { Type::TsqueryArray => {
@ -1263,7 +1231,7 @@ impl Type {
const V: &'static Kind = &Kind::Array(Type::Jsonb); const V: &'static Kind = &Kind::Array(Type::Jsonb);
V V
} }
Type::Anyrange => { Type::AnyRange => {
const V: &'static Kind = &Kind::Pseudo; const V: &'static Kind = &Kind::Pseudo;
V V
} }
@ -1296,7 +1264,7 @@ impl Type {
V V
} }
Type::TstzRange => { Type::TstzRange => {
const V: &'static Kind = &Kind::Range(Type::TimestampTZ); const V: &'static Kind = &Kind::Range(Type::Timestamptz);
V V
} }
Type::TstzRangeArray => { Type::TstzRangeArray => {
@ -1366,10 +1334,6 @@ impl Type {
Type::Cid => "cid", Type::Cid => "cid",
Type::OidVector => "oidvector", Type::OidVector => "oidvector",
Type::PgDdlCommand => "pg_ddl_command", Type::PgDdlCommand => "pg_ddl_command",
Type::PgType => "pg_type",
Type::PgAttribute => "pg_attribute",
Type::PgProc => "pg_proc",
Type::PgClass => "pg_class",
Type::Json => "json", Type::Json => "json",
Type::Xml => "xml", Type::Xml => "xml",
Type::XmlArray => "_xml", Type::XmlArray => "_xml",
@ -1436,8 +1400,8 @@ impl Type {
Type::TimestampArray => "_timestamp", Type::TimestampArray => "_timestamp",
Type::DateArray => "_date", Type::DateArray => "_date",
Type::TimeArray => "_time", Type::TimeArray => "_time",
Type::TimestampTZ => "timestamptz", Type::Timestamptz => "timestamptz",
Type::TimestampTZArray => "_timestamptz", Type::TimestamptzArray => "_timestamptz",
Type::Interval => "interval", Type::Interval => "interval",
Type::IntervalArray => "_interval", Type::IntervalArray => "_interval",
Type::NumericArray => "_numeric", Type::NumericArray => "_numeric",
@ -1482,11 +1446,11 @@ impl Type {
Type::PgLsnArray => "_pg_lsn", Type::PgLsnArray => "_pg_lsn",
Type::TsmHandler => "tsm_handler", Type::TsmHandler => "tsm_handler",
Type::Anyenum => "anyenum", Type::Anyenum => "anyenum",
Type::Tsvector => "tsvector", Type::TsVector => "tsvector",
Type::Tsquery => "tsquery", Type::Tsquery => "tsquery",
Type::Gtsvector => "gtsvector", Type::GtsVector => "gtsvector",
Type::TsvectorArray => "_tsvector", Type::TsVectorArray => "_tsvector",
Type::GtsvectorArray => "_gtsvector", Type::GtsVectorArray => "_gtsvector",
Type::TsqueryArray => "_tsquery", Type::TsqueryArray => "_tsquery",
Type::Regconfig => "regconfig", Type::Regconfig => "regconfig",
Type::RegconfigArray => "_regconfig", Type::RegconfigArray => "_regconfig",
@ -1494,7 +1458,7 @@ impl Type {
Type::RegdictionaryArray => "_regdictionary", Type::RegdictionaryArray => "_regdictionary",
Type::Jsonb => "jsonb", Type::Jsonb => "jsonb",
Type::JsonbArray => "_jsonb", Type::JsonbArray => "_jsonb",
Type::Anyrange => "anyrange", Type::AnyRange => "anyrange",
Type::EventTrigger => "event_trigger", Type::EventTrigger => "event_trigger",
Type::Int4Range => "int4range", Type::Int4Range => "int4range",
Type::Int4RangeArray => "_int4range", Type::Int4RangeArray => "_int4range",