Skip to content

Instantly share code, notes, and snippets.

@frankyston
Forked from ys/stored_procedure_service.rb
Created February 27, 2023 11:59
Show Gist options
  • Save frankyston/e59588bc7656d44705ad586ce8537517 to your computer and use it in GitHub Desktop.
Save frankyston/e59588bc7656d44705ad586ce8537517 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