Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arfi/extensions/active_record/base.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.function_exists?(function_name) ⇒ Boolean

ActiveRecord::Base.function_exists? -> bool

This method checks if a custom SQL function exists in the database.

Examples:

ActiveRecord::Base.function_exists?('my_function') #=> true
ActiveRecord::Base.function_exists?('my_function123') #=> false

Parameters:

  • function_name (String)

    The name of the function to check.

Returns:

  • (Boolean)

    Returns true if the function exists, false otherwise.



16
17
18
# File 'lib/arfi/extensions/active_record/base.rb', line 16

def self.function_exists?(function_name)
  connection.execute("SELECT * FROM pg_proc WHERE proname = '#{function_name}'").any?
end