Browse Source

Merge branch 'jsonb'

alisdair sullivan 10 years ago
parent
commit
4b2b33ebbe
4 changed files with 16 additions and 2 deletions
  1. 3 0
      src/epgsql_binary.erl
  2. 4 0
      src/epgsql_types.erl
  3. 7 1
      test/epgsql_tests.erl
  4. 2 1
      test_data/test_schema.sql

+ 3 - 0
src/epgsql_binary.erl

@@ -70,6 +70,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(json, B, _) when is_binary(B)        -> <<(byte_size(B)):?int32, B/binary>>;
+encode(jsonb, B, _) when is_binary(B)       -> <<(byte_size(B)):?int32, B/binary>>;
 encode(uuid, B, _) when is_binary(B)        -> encode_uuid(B);
 encode({array, char}, L, Codec) when is_list(L) -> encode_array(bpchar, type2oid(bpchar, Codec), L, Codec);
 encode({array, Type}, L, Codec) when is_list(L) -> encode_array(Type, type2oid(Type, Codec), L, Codec);
@@ -284,6 +285,7 @@ supports(inet)        -> true;
 supports(geometry)    -> true;
 supports(point)       -> true;
 supports(json)        -> true;
+supports(jsonb)       -> true;
 supports({array, bool})   -> true;
 supports({array, int2})   -> true;
 supports({array, int4})   -> true;
@@ -304,4 +306,5 @@ supports({array, uuid})   -> true;
 supports({array, cidr})   -> true;
 supports({array, inet})   -> true;
 supports({array, json})   -> true;
+supports({array, jsonb})  -> true;
 supports(_Type)       -> false.

+ 4 - 0
src/epgsql_types.erl

@@ -97,6 +97,8 @@ oid2type(2776)  -> anynonarray;
 oid2type(2950)  -> uuid;
 oid2type(2951)  -> {array, uuid};
 oid2type(3500)  -> anyenum;
+oid2type(3802)  -> jsonb;
+oid2type(3807)  -> {array, jsonb};
 oid2type(3904)  -> int4range;
 oid2type(Oid)   -> {unknown_oid, Oid}.
 
@@ -195,5 +197,7 @@ type2oid(anynonarray)           -> 2776;
 type2oid(uuid)                  -> 2950;
 type2oid({array, uuid})         -> 2951;
 type2oid(anyenum)               -> 3500;
+type2oid(jsonb)                 -> 3802;
+type2oid({array, jsonb})        -> 3807;
 type2oid(int4range)             -> 3904;
 type2oid(Type)                  -> {unknown_type, Type}.

+ 7 - 1
test/epgsql_tests.erl

@@ -565,6 +565,11 @@ json_type_test(Module) ->
       Module,
       fun(C) ->
               check_type(Module, json, "'{}'", <<"{}">>,
+<<<<<<< HEAD
+=======
+                         [<<"{}">>, <<"[]">>, <<"1">>, <<"1.0">>, <<"true">>, <<"\"string\"">>, <<"{\"key\": []}">>]),
+              check_type(Module, jsonb, "'{}'", <<"{}">>,
+>>>>>>> jsonb
                          [<<"{}">>, <<"[]">>, <<"1">>, <<"1.0">>, <<"true">>, <<"\"string\"">>, <<"{\"key\": []}">>])
       end
     ).
@@ -634,7 +639,8 @@ array_type_test(Module) ->
           Select(hstore, [[{[{null, null}, {a, 1}, {1, 2}, {b, undefined}]}, {[]}], [{[{a, 1}]}, {[{null, 2}]}]]),
           Select(cidr, [{{127,0,0,1}, 32}, {{0,0,0,0,0,0,0,1}, 128}]),
           Select(inet, [{127,0,0,1}, {0,0,0,0,0,0,0,1}]),
-          Select(json, [<<"{}">>, <<"[]">>, <<"1">>, <<"1.0">>, <<"true">>, <<"\"string\"">>, <<"{\"key\": []}">>])
+          Select(json, [<<"{}">>, <<"[]">>, <<"1">>, <<"1.0">>, <<"true">>, <<"\"string\"">>, <<"{\"key\": []}">>]),
+          Select(jsonb, [<<"{}">>, <<"[]">>, <<"1">>, <<"1.0">>, <<"true">>, <<"\"string\"">>, <<"{\"key\": []}">>])
       end).
 
 text_format_test(Module) ->

+ 2 - 1
test_data/test_schema.sql

@@ -64,7 +64,8 @@ CREATE TABLE test_table2 (
   c_cidr cidr,
   c_inet inet,
   c_int4range int4range,
-  c_json json);
+  c_json json,
+  c_jsonb jsonb);
 
 CREATE LANGUAGE plpgsql;