Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belgoros/a2264fceabd1594f20a46f1853c4599f to your computer and use it in GitHub Desktop.
Save belgoros/a2264fceabd1594f20a46f1853c4599f to your computer and use it in GitHub Desktop.
Execute stored procedure
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