Sha256: 1a2b92634fbf5742868da45beff97e246a72bda25f6729d930e1defdf2309bb9
Contents?: true
Size: 2 KB
Versions: 5
Compression:
Stored size: 2 KB
Contents
# -*- encoding : utf-8 -*- class Card::Query require_dependency 'card/query/clause' require_dependency 'card/query/card_clause' require_dependency 'card/query/value_clause' require_dependency 'card/query/ref_clause' MODIFIERS = {}; %w{ conj return sort sort_as group dir limit offset }.each{|key| MODIFIERS[key.to_sym] = nil } OPERATORS = %w{ != = =~ < > in ~ }.inject({}) {|h,v| h[v]=nil; h }.merge({ :eq => '=', :gt => '>', :lt => '<', :match => '~', :ne => '!=', 'not in' => nil }.stringify_keys) def initialize query @card_clause = CardClause.build query end def query @card_clause.query end def sql @sql ||= @card_clause.to_sql end def run # puts "~~~~~~~~~~~~~~\nCARD SPEC =\n#{@card_clause.rawclause}\n\n-----\n\nSQL=\n#{sql}" rows = ActiveRecord::Base.connection.select_all( sql ) retrn = query[:return].present? ? query[:return].to_s : 'card' case retrn when 'card' rows.map do |row| card= if query[:prepend] || query[:append] cardname = [query[:prepend], row['name'], query[:append]].compact.join('+') Card.fetch cardname, :new=>{} else Card[ row['name'] ] end card.nil? ? Card.find_by_name_and_trash(row['name'],false).repair_key : card end when 'count' rows.first['count'].to_i when 'raw' rows else rows.map { |row| row[retrn] } end end class SqlCond < String def to_sql(*args) self end end class SqlStatement attr_accessor :fields, :tables, :joins, :conditions, :group, :order, :limit, :offset def initialize @fields, @joins, @conditions = [],[],[],[] @tables, @group, @order, @limit, @offset = "","","","","" end def to_s select = fields.reject(&:blank?) * ', ' where = conditions.reject(&:blank?) * ' and ' ['(SELECT', select, 'FROM', tables, joins, 'WHERE', where, group, order, limit, offset, ')'].compact * ' ' end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
wagn-1.14.9 | lib/card/query.rb |
wagn-1.14.8 | lib/card/query.rb |
wagn-1.14.7 | lib/card/query.rb |
wagn-1.14.6 | lib/card/query.rb |
wagn-1.14.5 | lib/card/query.rb |