class Object

Public Class Methods

get_join_param(js) click to toggle source

Given an array, determine if it has the form

[join_table, join_on, data], …

or

join_table, join_on, data

Always return the former format

# File lib/qx.rb, line 411
def self.get_join_param(js)
  js.first.is_a?(Array) ? js : [[js.first, js[1], js[2]]]
end
get_where_params(ws) click to toggle source

Similar to get_joins_params, except each where clause is a pair, not a triplet

# File lib/qx.rb, line 427
def self.get_where_params(ws)
  ws.first.is_a?(Array) ? ws : [[ws.first, ws[1]]]
end
parse_val_params(vals) click to toggle source

given either a single, hash, array of hashes, or csv style, turn it all into csv style util for INSERT INTO x (y) VALUES z

# File lib/qx.rb, line 433
def self.parse_val_params(vals)
  if vals.is_a?(Array) && vals.first.is_a?(Array)
    cols = vals.first
    data = vals[1..-1]
  elsif vals.is_a?(Array) && vals.first.is_a?(Hash)
    hashes = vals.map{|h| h.sort.to_h}
    cols = hashes.first.keys
    data = hashes.map{|h| h.values}
  elsif vals.is_a?(Hash)
    cols = vals.keys
    data = [vals.values]
  end
  return [cols, data]
end
parse_wheres(clauses) click to toggle source

given either a single hash or a string expr + data, parse it into a single string expression

# File lib/qx.rb, line 416
def self.parse_wheres(clauses)
  clauses.map do |expr, data|
    if expr.is_a?(Hash)
      expr.map{|key, val| "#{Qx.quote_ident(key)} IN (#{Qx.quote(val)})"}.join(" AND ")
    else
      Qx.interpolate_expr(expr, data)
    end
  end
end