Skip to content

Commit

Permalink
Convert all database array types to Ruby arrays in the jdbc adapter
Browse files Browse the repository at this point in the history
This is done if convert_types is true for the Database, which is
the default (it can be set to false for better performance).

Remove the related code in the jdbc/postgresql adapter as it is
no longer needed.
  • Loading branch information
jeremyevans committed Aug 15, 2019
1 parent ab14b86 commit 5b5c884
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Convert all database array types to Ruby arrays in the jdbc adapter (jeremyevans)

* Add static_cache_cache plugin for caching rows for static_cache models to a file to avoid database queries during model initialization (jeremyevans)

* Add :cache_file plugin option to pg_auto_constraint_validations plugin, for caching metadata to a file for faster initialization (jeremyevans)
Expand Down
8 changes: 7 additions & 1 deletion lib/sequel/adapters/jdbc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ def x.call(r, i)
v.getSubString(1, v.length)
end
end
x = convertors[:RubyArray] = Object.new
def x.call(r, i)
if v = r.getArray(i)
v.array.to_ary
end
end

MAP = Hash.new(convertors[:Object])
types = Java::JavaSQL::Types

{
:ARRAY => :Array,
:BOOLEAN => :Boolean,
:CHAR => :String,
:DOUBLE => :Double,
Expand All @@ -126,6 +131,7 @@ def x.call(r, i)
BASIC_MAP = MAP.dup

{
:ARRAY => :Array,
:BINARY => :Blob,
:BLOB => :Blob,
:CLOB => :Clob,
Expand Down
14 changes: 1 addition & 13 deletions lib/sequel/adapters/jdbc/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,7 @@ def literal_sqltime(v)

STRING_TYPE = Java::JavaSQL::Types::VARCHAR
ARRAY_TYPE = Java::JavaSQL::Types::ARRAY
PG_SPECIFIC_TYPES = [ARRAY_TYPE, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT, Java::JavaSQL::Types::TIME_WITH_TIMEZONE, Java::JavaSQL::Types::TIME].freeze

# Return PostgreSQL array types as ruby Arrays instead of
# JDBC PostgreSQL driver-specific array type. Only used if the
# database does not have a conversion proc for the type.
ARRAY_METHOD = Object.new
def ARRAY_METHOD.call(r, i)
if v = r.getArray(i)
v.array.to_ary
end
end
PG_SPECIFIC_TYPES = [Java::JavaSQL::Types::ARRAY, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT, Java::JavaSQL::Types::TIME_WITH_TIMEZONE, Java::JavaSQL::Types::TIME].freeze

# Return PostgreSQL hstore types as ruby Hashes instead of
# Java HashMaps. Only used if the database does not have a
Expand All @@ -223,8 +213,6 @@ def type_convertor(map, meta, type, i)
oid = meta.getField(i).getOID
if pr = db.oid_convertor_proc(oid)
pr
elsif type == ARRAY_TYPE
ARRAY_METHOD
elsif oid == 2950 # UUID
map[STRING_TYPE]
elsif meta.getPGType(i) == 'hstore'
Expand Down

0 comments on commit 5b5c884

Please sign in to comment.