module SchemaPlus::Functions::ActiveRecord::ConnectionAdapters::AbstractAdapter

Public Instance Methods

create_function(function_name, params, definition, options = {}) click to toggle source

Create a function. Valid options are :force, :allow_replace, and :function_type

# File lib/schema_plus/functions/active_record/connection_adapters/abstract_adapter.rb, line 9
def create_function(function_name, params, definition, options = {})
  SchemaMonkey::Middleware::Migration::CreateFunction.start(connection: self, function_name: function_name, params: params, definition: definition, options: options) do |env|
    function_name = env.function_name
    function_type = (options[:function_type] || :function).to_s.upcase
    params        = env.params
    definition    = env.definition
    options       = env.options

    definition    = definition.to_sql if definition.respond_to? :to_sql
    if options[:force]
      drop_function(function_name, params, function_type: options[:function_type], if_exists: true)
    end

    command = if options[:allow_replace]
                "CREATE OR REPLACE"
              else
                "CREATE"
              end
    execute "#{command} #{function_type} #{function_name}(#{params}) #{definition}"
  end
end
drop_function(function_name, params, options = {}) click to toggle source

Remove a function. Valid options are :function_type, :if_exists, and :cascade

If your function type is an aggregate, you must specify the type

drop_function 'my_func', 'int', if_exists: true, cascade: true
drop_function 'my_agg', 'int', function_type: :aggregate
# File lib/schema_plus/functions/active_record/connection_adapters/abstract_adapter.rb, line 38
def drop_function(function_name, params, options = {})
  SchemaMonkey::Middleware::Migration::CreateFunction.start(connection: self, function_name: function_name, params: params, options: options) do |env|
    function_name = env.function_name
    params        = env.params
    options       = env.options
    function_type = (options[:function_type] || :function).to_s.upcase

    sql = "DROP #{function_type}"
    sql += " IF EXISTS" if options[:if_exists]
    sql += " #{function_name}(#{params})"
    sql += " CASCADE" if options[:cascade]

    execute sql
  end
end
function_definition(function_name, params, name = nil) click to toggle source

(abstract) Return the Function definition for the named function and parameter set

# File lib/schema_plus/functions/active_record/connection_adapters/abstract_adapter.rb, line 66
def function_definition(function_name, params, name = nil)
  raise "Internal Error: Connection adapter did not override abstract function"
end
functions(name = nil) click to toggle source

(abstract) Return the Function objects for functions

# File lib/schema_plus/functions/active_record/connection_adapters/abstract_adapter.rb, line 61
def functions(name = nil)
  raise "Internal Error: Connection adapter did not override abstract function"
end