lib/crate_ruby/client.rb in crate_ruby-0.0.4 vs lib/crate_ruby/client.rb in crate_ruby-0.0.5
- old
+ new
@@ -69,14 +69,17 @@
execute("select table_name from information_schema.tables where schema_name = 'doc'").map(&:first)
end
# Executes a SQL statement against the Crate HTTP REST endpoint.
# @param [String] sql statement to execute
+ # @param [Array] args Array of values used for parameter substitution
# @return [ResultSet]
- def execute(sql)
+ def execute(sql, args = nil)
@logger.debug sql
req = Net::HTTP::Post.new("/_sql", initheader = {'Content-Type' => 'application/json'})
- req.body = {"stmt" => sql}.to_json
+ body = {"stmt" => sql}
+ body.merge!({'args' => args}) if args
+ req.body = body.to_json
response = request(req)
@logger.debug response.body
success = case response.code
when /^2\d{2}/
ResultSet.new response.body
\ No newline at end of file