lesser logging. order-bug fixed
This commit is contained in:
parent
8eeb66d99f
commit
5c68b74ee4
|
@ -180,35 +180,35 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
benchmark 'SMQL parse' do
|
#benchmark 'SMQL parse' do
|
||||||
@conditions = ConditionTypes.try_parse @model, @query
|
@conditions = ConditionTypes.try_parse @model, @query
|
||||||
end
|
#end
|
||||||
#p conditions: @conditions
|
#p conditions: @conditions
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def build
|
def build
|
||||||
benchmark 'SMQL build query' do
|
#benchmark 'SMQL build query' do
|
||||||
@builder = QueryBuilder.new @model
|
@builder = QueryBuilder.new @model
|
||||||
table = @builder.base_table
|
table = @builder.base_table
|
||||||
@conditions.each {|condition| condition.build builder, table }
|
@conditions.each {|condition| condition.build builder, table }
|
||||||
end
|
#end
|
||||||
#p builder: @builder
|
#p builder: @builder
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def ar
|
def ar
|
||||||
@ar ||= benchmark 'SMQL ar' do
|
@ar ||= #benchmark 'SMQL ar' do
|
||||||
@builder.to_ar
|
@builder.to_ar
|
||||||
end
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_ar
|
def to_ar
|
||||||
benchmark 'SMQL' do
|
#benchmark 'SMQL' do
|
||||||
parse
|
parse
|
||||||
build
|
build
|
||||||
ar
|
ar
|
||||||
end
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.to_ar *params
|
def self.to_ar *params
|
||||||
|
|
|
@ -213,7 +213,7 @@ class SmqlToAR
|
||||||
@cols.each do |col, sub|
|
@cols.each do |col, sub|
|
||||||
t = table + col.path + [col.col]
|
t = table + col.path + [col.col]
|
||||||
#p sub: sub
|
#p sub: sub
|
||||||
p col: col, joins: col.joins
|
#p col: col, joins: col.joins
|
||||||
col.joins.each {|j, m| builder.join table+j, m }
|
col.joins.each {|j, m| builder.join table+j, m }
|
||||||
builder.join t, SmqlToAR.model_of( col.last_model, col.col)
|
builder.join t, SmqlToAR.model_of( col.last_model, col.col)
|
||||||
sub[1..-1].each {|one| one.build builder, t }
|
sub[1..-1].each {|one| one.build builder, t }
|
||||||
|
@ -263,7 +263,7 @@ class SmqlToAR
|
||||||
attr_reader :model, :func, :args
|
attr_reader :model, :func, :args
|
||||||
|
|
||||||
def self.try_parse model, func, args
|
def self.try_parse model, func, args
|
||||||
SmqlToAR.logger.info( { try_parse: [func,args]}.inspect)
|
#SmqlToAR.logger.info( { try_parse: [func,args]}.inspect)
|
||||||
self.new model, func, args if self::Name === func and self::Expected.any? {|e| e === args }
|
self.new model, func, args if self::Name === func and self::Expected.any? {|e| e === args }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -277,14 +277,14 @@ class SmqlToAR
|
||||||
Expected = [String, Array, Hash, nil]
|
Expected = [String, Array, Hash, nil]
|
||||||
|
|
||||||
def initialize model, func, args
|
def initialize model, func, args
|
||||||
SmqlToAR.logger.info( {args: args}.inspect)
|
#SmqlToAR.logger.info( {args: args}.inspect)
|
||||||
args = case args
|
args = case args
|
||||||
when String then [args]
|
when String then [args]
|
||||||
when Array, Hash then args.to_a
|
when Array, Hash then args.to_a
|
||||||
when nil then nil
|
when nil then nil
|
||||||
else raise 'Oops'
|
else raise 'Oops'
|
||||||
end
|
end
|
||||||
SmqlToAR.logger.info( {args: args}.inspect)
|
#SmqlToAR.logger.info( {args: args}.inspect)
|
||||||
args.andand.collect! do |o|
|
args.andand.collect! do |o|
|
||||||
o = Array.wrap o
|
o = Array.wrap o
|
||||||
col = Column.new model, o.first
|
col = Column.new model, o.first
|
||||||
|
@ -292,7 +292,7 @@ class SmqlToAR
|
||||||
raise NonExistingColumnError.new( [:Column], col) unless col.exist_in?
|
raise NonExistingColumnError.new( [:Column], col) unless col.exist_in?
|
||||||
[col, o]
|
[col, o]
|
||||||
end
|
end
|
||||||
SmqlToAR.logger.info( {args: args}.inspect)
|
#SmqlToAR.logger.info( {args: args}.inspect)
|
||||||
super model, func, args
|
super model, func, args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -309,15 +309,15 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new model, col, val
|
def self.new model, col, val
|
||||||
SmqlToAR.logger.info( { function: col.first.to_sym }.inspect)
|
#SmqlToAR.logger.info( { function: col.first.to_sym }.inspect)
|
||||||
r = nil
|
r = nil
|
||||||
constants.each do |c|
|
constants.each do |c|
|
||||||
next if [:Function, :Where, :Expected, :Operator].include? c
|
next if [:Function, :Where, :Expected, :Operator].include? c
|
||||||
c = const_get c
|
c = const_get c
|
||||||
next if Function === c or not c.respond_to?( :try_parse)
|
next if Function === c or not c.respond_to?( :try_parse)
|
||||||
SmqlToAR.logger.info( {f: c}.inspect)
|
#SmqlToAR.logger.info( {f: c}.inspect)
|
||||||
r = c.try_parse model, col.first.to_sym, val
|
r = c.try_parse model, col.first.to_sym, val
|
||||||
SmqlToAR.logger.info( {r: r}.inspect)
|
#SmqlToAR.logger.info( {r: r}.inspect)
|
||||||
break if r
|
break if r
|
||||||
end
|
end
|
||||||
r
|
r
|
||||||
|
|
|
@ -111,7 +111,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
|
|
||||||
def order table, col, o
|
def order table, col, o
|
||||||
tc = column table, col
|
ct = column table, col
|
||||||
@_select.push ct
|
@_select.push ct
|
||||||
@_order.push "#{ct} #{:DESC == o ? :DESC : :ASC}"
|
@_order.push "#{ct} #{:DESC == o ? :DESC : :ASC}"
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in a new issue