lib/rom/sql/gateway.rb in rom-sql-0.8.0 vs lib/rom/sql/gateway.rb in rom-sql-0.9.0
- old
+ new
@@ -21,10 +21,14 @@
class << self
attr_accessor :instance
end
+ CONNECTION_EXTENSIONS = {
+ postgres: %i(pg_array pg_json)
+ }.freeze
+
# Return optionally configured logger
#
# @return [Object] logger
#
# @api public
@@ -54,11 +58,11 @@
def initialize(uri, options = {})
repo_options = self.class.option_definitions.names
conn_options = options.reject { |k, _| repo_options.include?(k) }
@connection = connect(uri, conn_options)
- add_extensions(Array(options[:extensions])) if options[:extensions]
+ load_extensions(Array(options[:extensions]))
super(uri, options.reject { |k, _| conn_options.keys.include?(k) })
self.class.instance = self
end
@@ -175,14 +179,21 @@
else
::Sequel.connect(uri.to_s, *args)
end
end
- # Add extensions to the database connection
+ # Load database-specific extensions
#
# @api private
- def add_extensions(exts)
- connection.extension(*exts)
+ def load_extensions(exts)
+ db_type = connection.database_type.to_sym
+
+ if ROM::SQL.available_extension?(db_type)
+ ROM::SQL.load_extensions(db_type)
+ end
+
+ extensions = (CONNECTION_EXTENSIONS.fetch(db_type) { [] } + exts).uniq
+ connection.extension(*extensions)
end
end
end
end