lib/rom/sql/gateway.rb in rom-sql-2.0.0.beta2 vs lib/rom/sql/gateway.rb in rom-sql-2.0.0.beta3
- old
+ new
@@ -1,6 +1,7 @@
require 'logger'
+require 'sequel/core'
require 'dry/core/constants'
require 'rom/types'
require 'rom/gateway'
@@ -29,27 +30,10 @@
# @!attribute [r] options
# @return [Hash] Options used for connection
attr_reader :options
- subscribe('configuration.commands.class.before_build') do |event|
- klass = event[:command]
- dataset = event[:dataset]
- type = dataset.db.database_type
-
- if type == :postgres
- ext =
- if klass < Commands::Create
- Commands::Postgres::Create
- elsif klass < Commands::Update
- Commands::Postgres::Update
- end
-
- klass.send(:include, ext) if ext
- end
- end
-
# Initialize an SQL gateway
#
# Gateways are typically initialized via ROM::Configuration object, gateway constructor
# arguments such as URI and options are passed directly to this constructor
#
@@ -69,18 +53,10 @@
#
# @param [String,Symbol] uri connection URI
#
# @param [Hash] options connection options
#
- # @option options [Array<Symbol>] :inferrable_relations
- # A list of dataset names that should be inferred. If
- # this is set explicitly to an empty array relations
- # won't be inferred at all
- #
- # @option options [Array<Symbol>] :not_inferrable_relations
- # A list of dataset names that should NOT be inferred
- #
# @option options [Array<Symbol>] :extensions
# A list of connection extensions supported by Sequel
#
# @option options [String] :user Database username
#
@@ -116,11 +92,11 @@
connection.disconnect
end
# Return dataset with the given name
#
- # Thsi returns a raw Sequel database
+ # This returns a raw Sequel database
#
# @param [String, Symbol] name The dataset name
#
# @return [Dataset]
#
@@ -198,9 +174,33 @@
# @return [Symbol]
#
# @api public
def database_type
@database_type ||= connection.database_type.to_sym
+ end
+
+ # Call a SQL function
+ #
+ # @example
+ # gateway.(:upper, 'John Doe') # => "JOHN DOE"
+ #
+ # @param [Symbol] function Function name
+ # @param [Array<Object>] args Function arguments
+ #
+ # @return [Object]
+ #
+ # @api public
+ def call(function, *args)
+ connection[Sequel.function(function, *args)].first.values.first
+ end
+
+ # Execute a statement
+ #
+ # @param [String] statement
+ #
+ # @api public
+ def run(statement)
+ connection.run(statement)
end
private
# Connect to database or reuse established connection instance