-
-
Save frankyston/e59588bc7656d44705ad586ce8537517 to your computer and use it in GitHub Desktop.
Execute stored procedure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StoredProcedureService | |
def self.instance | |
@instance ||= StoredProcedureService.new | |
end | |
def execute(name, *args) | |
results = [] | |
begin | |
connection.execute("CALL #{name}(#{args.join(',')})").each(as: :hash, symbolize_keys: true) do |row| | |
results << OpenStruct.new(row) | |
end | |
ensure | |
connection.close | |
end | |
results | |
end | |
def connection | |
ActiveRecord::Base.connection | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment