Browse Source

Change array types naming convention from typearray to {array, type}

bullno1 11 years ago
parent
commit
a3ffc217bb
2 changed files with 54 additions and 82 deletions
  1. 18 46
      src/pgsql_binary.erl
  2. 36 36
      src/pgsql_types.erl

+ 18 - 46
src/pgsql_binary.erl

@@ -28,21 +28,7 @@ encode(bytea, B) when is_binary(B)          -> <<(byte_size(B)):?int32, B/binary
 encode(text, B) when is_binary(B)           -> <<(byte_size(B)):?int32, B/binary>>;
 encode(varchar, B) when is_binary(B)        -> <<(byte_size(B)):?int32, B/binary>>;
 encode(uuid, B) when is_binary(B)           -> encode_uuid(B);
-encode(boolarray, L) when is_list(L)        -> encode_array(bool, L);
-encode(int2array, L) when is_list(L)        -> encode_array(int2, L);
-encode(int4array, L) when is_list(L)        -> encode_array(int4, L);
-encode(int8array, L) when is_list(L)        -> encode_array(int8, L);
-encode(float4array, L) when is_list(L)      -> encode_array(float4, L);
-encode(float8array, L) when is_list(L)      -> encode_array(float8, L);
-encode(chararray, L) when is_list(L)        -> encode_array(bpchar, L);
-encode(textarray, L) when is_list(L)        -> encode_array(text, L);
-encode(datearray, L) when is_list(L)        -> encode_array(date, L);
-encode(timearray, L) when is_list(L)        -> encode_array(time, L);
-encode(timetzarray, L) when is_list(L)      -> encode_array(timetz, L);
-encode(timestamparray, L) when is_list(L)   -> encode_array(timestamp, L);
-encode(timestamptzarray, L) when is_list(L) -> encode_array(timestamptz, L);
-encode(intervalarray, L) when is_list(L)    -> encode_array(interval, L);
-encode(uuidarray, L) when is_list(L)        -> encode_array(uuid, L);
+encode({array, Type}, L) when is_list(L)    -> encode_array(Type, L);
 encode(Type, L) when is_list(L)             -> encode(Type, list_to_binary(L));
 encode(_Type, _Value)                       -> {error, unsupported}.
 
@@ -62,21 +48,7 @@ decode(timestamp = Type, B)                 -> ?datetime:decode(Type, B);
 decode(timestamptz = Type, B)               -> ?datetime:decode(Type, B);
 decode(interval = Type, B)                  -> ?datetime:decode(Type, B);
 decode(uuid, B)                             -> decode_uuid(B);
-decode(boolarray, B)                        -> decode_array(B);
-decode(int2array, B)                        -> decode_array(B);
-decode(int4array, B)                        -> decode_array(B);
-decode(int8array, B)                        -> decode_array(B);
-decode(float4array, B)                      -> decode_array(B);
-decode(float8array, B)                      -> decode_array(B);
-decode(chararray, B)                        -> decode_array(B);
-decode(textarray, B)                        -> decode_array(B);
-decode(datearray, B)                        -> decode_array(B);
-decode(timearray, B)                        -> decode_array(B);
-decode(timetzarray, B)                      -> decode_array(B);
-decode(timestamparray, B)                   -> decode_array(B);
-decode(timestamptzarray, B)                 -> decode_array(B);
-decode(intervalarray, B)                    -> decode_array(B);
-decode(uuidarray, B)                        -> decode_array(B);
+decode({array, _Type}, B)                   -> decode_array(B);
 decode(_Other, Bin)                         -> Bin.
 
 encode_array(Type, A) ->
@@ -163,20 +135,20 @@ supports(timestamp)   -> true;
 supports(timestamptz) -> true;
 supports(interval)    -> true;
 supports(uuid)        -> true;
-supports(boolarray)   -> true;
-supports(int2array)   -> true;
-supports(int4array)   -> true;
-supports(int8array)   -> true;
-supports(float4array) -> true;
-supports(float8array) -> true;
-supports(chararray)   -> true;
-supports(textarray)   -> true;
-supports(datearray)   -> true;
-supports(timearray)   -> true;
-supports(timetzarray) -> true;
-supports(timestamparray)     -> true;
-supports(timestamptzarray)   -> true;
-supports(intervalarray)      -> true;
-supports(varchararray) -> true;
-supports(uuidarray)   -> true;
+supports({array, bool})   -> true;
+supports({array, int2})   -> true;
+supports({array, int4})   -> true;
+supports({array, int8})   -> true;
+supports({array, float4}) -> true;
+supports({array, float8}) -> true;
+supports({array, char})   -> true;
+supports({array, text})   -> true;
+supports({array, date})   -> true;
+supports({array, time})   -> true;
+supports({array, timetz}) -> true;
+supports({array, timestamp})     -> true;
+supports({array, timestamptz})   -> true;
+supports({array, interval})      -> true;
+supports({array, varchar}) -> true;
+supports({array, uuid})   -> true;
 supports(_Type)       -> false.

+ 36 - 36
src/pgsql_types.erl

@@ -39,30 +39,30 @@ oid2type(790)  -> cash;
 oid2type(829)  -> macaddr;
 oid2type(869)  -> inet;
 oid2type(650)  -> cidr;
-oid2type(1000) -> boolarray;
-oid2type(1005) -> int2array;
-oid2type(1007) -> int4array;
-oid2type(1009) -> textarray;
-oid2type(1014) -> chararray;
-oid2type(1016) -> int8array;
-oid2type(1021) -> float4array;
-oid2type(1022) -> float8array;
+oid2type(1000) -> {array, bool};
+oid2type(1005) -> {array, int2};
+oid2type(1007) -> {array, int4};
+oid2type(1009) -> {array, text};
+oid2type(1014) -> {array, char};
+oid2type(1016) -> {array, int8};
+oid2type(1021) -> {array, float4};
+oid2type(1022) -> {array, float8};
 oid2type(1033) -> aclitem;
-oid2type(1263) -> cstringarray;
+oid2type(1263) -> {array, cstring};
 oid2type(1042) -> bpchar;
 oid2type(1043) -> varchar;
 oid2type(1082) -> date;
 oid2type(1083) -> time;
 oid2type(1114) -> timestamp;
-oid2type(1115) -> timestamparray;
-oid2type(1182) -> datearray;
-oid2type(1183) -> timearray;
+oid2type(1115) -> {array, timestamp};
+oid2type(1182) -> {array, date};
+oid2type(1183) -> {array, time};
 oid2type(1184) -> timestamptz;
-oid2type(1185) -> timestamptzarray;
+oid2type(1185) -> {array, timestamptz};
 oid2type(1186) -> interval;
-oid2type(1187) -> intervalarray;
+oid2type(1187) -> {array, interval};
 oid2type(1266) -> timetz;
-oid2type(1270) -> timetzarray;
+oid2type(1270) -> {array, timetz};
 oid2type(1560) -> bit;
 oid2type(1562) -> varbit;
 oid2type(1700) -> numeric;
@@ -72,7 +72,7 @@ oid2type(2203) -> regoper;
 oid2type(2204) -> regoperator;
 oid2type(2205) -> regclass;
 oid2type(2206) -> regtype;
-oid2type(2211) -> regtypearray;
+oid2type(2211) -> {array, regtype};
 oid2type(3614) -> tsvector;
 oid2type(3642) -> gtsvector;
 oid2type(3615) -> tsquery;
@@ -81,7 +81,7 @@ oid2type(3769) -> regdictionary;
 oid2type(2249) -> record;
 oid2type(2275) -> cstring;
 oid2type(2276) -> any;
-oid2type(2277) -> anyarray;
+oid2type(2277) -> {array, any};
 oid2type(2278) -> void;
 oid2type(2279) -> trigger;
 oid2type(2280) -> language_handler;
@@ -90,7 +90,7 @@ oid2type(2282) -> opaque;
 oid2type(2283) -> anyelement;
 oid2type(2776) -> anynonarray;
 oid2type(2950) -> uuid;
-oid2type(2951) -> uuidarray;
+oid2type(2951) -> {array, uuid};
 oid2type(3500) -> anyenum;
 oid2type(Oid)  -> {unknown_oid, Oid}.
 
@@ -131,30 +131,30 @@ type2oid(cash)                  -> 790;
 type2oid(macaddr)               -> 829;
 type2oid(inet)                  -> 869;
 type2oid(cidr)                  -> 650;
-type2oid(boolarray)             -> 1000;
-type2oid(int2array)             -> 1005;
-type2oid(int4array)             -> 1007;
-type2oid(textarray)             -> 1009;
-type2oid(chararray)             -> 1014;
-type2oid(int8array)             -> 1016;
-type2oid(float4array)           -> 1021;
-type2oid(float8array)           -> 1022;
+type2oid({array, bool})         -> 1000;
+type2oid({array, int2})         -> 1005;
+type2oid({array, int4})         -> 1007;
+type2oid({array, text})         -> 1009;
+type2oid({array, char})         -> 1014;
+type2oid({array, int8})         -> 1016;
+type2oid({array, float4})       -> 1021;
+type2oid({array, float8})       -> 1022;
 type2oid(aclitem)               -> 1033;
-type2oid(cstringarray)          -> 1263;
+type2oid({array, cstring})      -> 1263;
 type2oid(bpchar)                -> 1042;
 type2oid(varchar)               -> 1043;
 type2oid(date)                  -> 1082;
 type2oid(time)                  -> 1083;
 type2oid(timestamp)             -> 1114;
-type2oid(timestamparray)        -> 1115;
-type2oid(datearray)             -> 1182;
-type2oid(timearray)             -> 1183;
+type2oid({array, timestamp})    -> 1115;
+type2oid({array, date})         -> 1182;
+type2oid({array, time})         -> 1183;
 type2oid(timestamptz)           -> 1184;
-type2oid(timestamptzarray)      -> 1185;
+type2oid({array, timestamptz})  -> 1185;
 type2oid(interval)              -> 1186;
-type2oid(intervalarray)         -> 1187;
+type2oid({array, interval})     -> 1187;
 type2oid(timetz)                -> 1266;
-type2oid(timetzarray)           -> 1270;
+type2oid({array, timetz})       -> 1270;
 type2oid(bit)                   -> 1560;
 type2oid(varbit)                -> 1562;
 type2oid(numeric)               -> 1700;
@@ -164,7 +164,7 @@ type2oid(regoper)               -> 2203;
 type2oid(regoperator)           -> 2204;
 type2oid(regclass)              -> 2205;
 type2oid(regtype)               -> 2206;
-type2oid(regtypearray)          -> 2211;
+type2oid({array, regtype})      -> 2211;
 type2oid(tsvector)              -> 3614;
 type2oid(gtsvector)             -> 3642;
 type2oid(tsquery)               -> 3615;
@@ -173,7 +173,7 @@ type2oid(regdictionary)         -> 3769;
 type2oid(record)                -> 2249;
 type2oid(cstring)               -> 2275;
 type2oid(any)                   -> 2276;
-type2oid(anyarray)              -> 2277;
+type2oid({array, any})          -> 2277;
 type2oid(void)                  -> 2278;
 type2oid(trigger)               -> 2279;
 type2oid(language_handler)      -> 2280;
@@ -182,6 +182,6 @@ type2oid(opaque)                -> 2282;
 type2oid(anyelement)            -> 2283;
 type2oid(anynonarray)           -> 2776;
 type2oid(uuid)                  -> 2950;
-type2oid(uuidarray)             -> 2951;
+type2oid({array, uuid})         -> 2951;
 type2oid(anyenum)               -> 3500;
 type2oid(Type)                  -> {unknown_type, Type}.