class Yaasql::Query
Attributes
arguments[R]
body[R]
name[R]
Public Class Methods
from_string(query)
click to toggle source
# File lib/yaasql/query.rb, line 7 def self.from_string(query) new(Reader.new.components(query)) end
new(components)
click to toggle source
# File lib/yaasql/query.rb, line 11 def initialize(components) [:body, :name, :arguments].each do |param| raise ArgumentError.new("Query missing component #{param}") unless components[param] end @body = components[:body] @name = components[:name] @arguments = components[:arguments] end
Public Instance Methods
execute(connection, args = {})
click to toggle source
# File lib/yaasql/query.rb, line 29 def execute(connection, args = {}) params = self.arguments.map { |a| prepare(args.fetch(a)) } connection.exec_params(body, params).to_a end
prepare(argument)
click to toggle source
# File lib/yaasql/query.rb, line 20 def prepare(argument) case argument when Array "{#{argument.join(",")}}" else argument end end