v0.0.5.2. build-methods renamed to an underscored class-name with suffix _build and aliases build to these methods created. equal_join_build fixed; it never use col.joins.each. #foreigh_key
This commit is contained in:
parent
fbf5a7019c
commit
ce81d21bd8
3 changed files with 33 additions and 23 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.0.5.1
|
0.0.5.2
|
||||||
|
|
|
@ -153,7 +153,7 @@ class SmqlToAR
|
||||||
# 2) {"givenname=", ["Peter", "Hans"]} #=> ( givenname = 'Peter' OR givenname = 'Hans' )
|
# 2) {"givenname=", ["Peter", "Hans"]} #=> ( givenname = 'Peter' OR givenname = 'Hans' )
|
||||||
# 3) {"givenname|surname=", ["Peter", "Mueller"]}
|
# 3) {"givenname|surname=", ["Peter", "Mueller"]}
|
||||||
# #=> ( givenname = 'Peter' OR surname = 'Peter' ) AND ( givenname = 'Mueller' OR surname = 'Mueller' )
|
# #=> ( givenname = 'Peter' OR surname = 'Peter' ) AND ( givenname = 'Mueller' OR surname = 'Mueller' )
|
||||||
def build builder, table
|
def condition_build builder, table
|
||||||
values = Hash[ @value.collect {|value| [ builder.vid, value ] } ]
|
values = Hash[ @value.collect {|value| [ builder.vid, value ] } ]
|
||||||
values.each {|k, v| builder.wobs k.to_sym => v }
|
values.each {|k, v| builder.wobs k.to_sym => v }
|
||||||
if 1 == @cols.length
|
if 1 == @cols.length
|
||||||
|
@ -174,6 +174,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias build condition_build
|
||||||
end
|
end
|
||||||
|
|
||||||
class NotInRange < Condition
|
class NotInRange < Condition
|
||||||
|
@ -190,7 +191,7 @@ class SmqlToAR
|
||||||
super model, cols, val
|
super model, cols, val
|
||||||
end
|
end
|
||||||
|
|
||||||
def build builder, table
|
def not_in_range_build builder, table
|
||||||
builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
|
builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
|
||||||
@cols.each do |col|
|
@cols.each do |col|
|
||||||
col.joins builder, table
|
col.joins builder, table
|
||||||
|
@ -198,11 +199,12 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias build not_in_range_build
|
||||||
end
|
end
|
||||||
InRange = simple_condition NotInRange, '..', '%s BETWEEN %s AND %s'
|
InRange = simple_condition NotInRange, '..', '%s BETWEEN %s AND %s'
|
||||||
|
|
||||||
class NotOverlaps < Condition
|
class Overlaps < Condition
|
||||||
Operator, Where = '<!>', 'NOT (%s, %s) OVERLAPS (%s, %s)'
|
Operator, Where = '<=>', '(%s, %s) OVERLAPS (%s, %s)'
|
||||||
Expected = [Range, lambda {|val|
|
Expected = [Range, lambda {|val|
|
||||||
Array === val && 2 == val.length &&
|
Array === val && 2 == val.length &&
|
||||||
[Time, Date, String].any? {|v|v===val[0]} &&
|
[Time, Date, String].any? {|v|v===val[0]} &&
|
||||||
|
@ -225,7 +227,7 @@ class SmqlToAR
|
||||||
super model, cols, val
|
super model, cols, val
|
||||||
end
|
end
|
||||||
|
|
||||||
def build builder, table
|
def overlaps_build builder, table
|
||||||
builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
|
builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
|
||||||
v1 = "TIMESTAMP #{v1}"
|
v1 = "TIMESTAMP #{v1}"
|
||||||
v2 = "TIMESTAMP #{v2}"
|
v2 = "TIMESTAMP #{v2}"
|
||||||
|
@ -236,15 +238,16 @@ class SmqlToAR
|
||||||
builder.column( table+f.path, f.col), builder.column( table+s.path, s.col), v1, v2]
|
builder.column( table+f.path, f.col), builder.column( table+s.path, s.col), v1, v2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
alias build overlaps_build
|
||||||
end
|
end
|
||||||
Overlaps = simple_condition NotOverlaps, '<=>', '(%s, %s) OVERLAPS (%s, %s)'
|
NotOverlaps = simple_condition Overlaps, '<=>', 'NOT (%s, %s) OVERLAPS (%s, %s)'
|
||||||
|
|
||||||
class NotIn < Condition
|
class NotIn < Condition
|
||||||
Operator = '!|='
|
Operator = '!|='
|
||||||
Where = "%s NOT IN (%s)"
|
Where = "%s NOT IN (%s)"
|
||||||
Expected = [Array]
|
Expected = [Array]
|
||||||
|
|
||||||
def build builder, table
|
def not_in_build builder, table
|
||||||
builder.wobs (v = builder.vid).to_sym => @value
|
builder.wobs (v = builder.vid).to_sym => @value
|
||||||
@cols.each do |col|
|
@cols.each do |col|
|
||||||
col.joins builder, table
|
col.joins builder, table
|
||||||
|
@ -252,6 +255,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias build not_in_build
|
||||||
end
|
end
|
||||||
|
|
||||||
In = simple_condition NotIn, '|=', '%s IN (%s)', [Array]
|
In = simple_condition NotIn, '|=', '%s IN (%s)', [Array]
|
||||||
|
@ -290,7 +294,7 @@ class SmqlToAR
|
||||||
raise_unless col.relation, NonExistingRelationError.new( %w[Relation], col)
|
raise_unless col.relation, NonExistingRelationError.new( %w[Relation], col)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build builder, table
|
def equal_join_build builder, table
|
||||||
if 2 < @cols.first.second.length
|
if 2 < @cols.first.second.length
|
||||||
b2, b3 = And, Or
|
b2, b3 = And, Or
|
||||||
else
|
else
|
||||||
|
@ -300,7 +304,7 @@ class SmqlToAR
|
||||||
@cols.each do |col, sub|
|
@cols.each do |col, sub|
|
||||||
model, *sub = sub
|
model, *sub = sub
|
||||||
t = table + col.path + [col.col]
|
t = table + col.path + [col.col]
|
||||||
col.joins.each {|j, m| builder.joins table+j, m }
|
col.joins builder, table
|
||||||
builder.joins t, model
|
builder.joins t, model
|
||||||
b4 = b3.new( b2)
|
b4 = b3.new( b2)
|
||||||
sub.each do |i|
|
sub.each do |i|
|
||||||
|
@ -310,6 +314,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias build equal_join_build
|
||||||
end
|
end
|
||||||
|
|
||||||
# Takes to Queries.
|
# Takes to Queries.
|
||||||
|
@ -339,7 +344,7 @@ class SmqlToAR
|
||||||
raise_unless col.child?, ConColumnError.new( [:Column], col)
|
raise_unless col.child?, ConColumnError.new( [:Column], col)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build builder, table
|
def sub_equal_join_build builder, table
|
||||||
@cols.each do |col, sub|
|
@cols.each do |col, sub|
|
||||||
t = table+col.to_a
|
t = table+col.to_a
|
||||||
builder.sub_joins t, col, *sub[0..1]
|
builder.sub_joins t, col, *sub[0..1]
|
||||||
|
@ -348,6 +353,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias build sub_equal_join_build
|
||||||
end
|
end
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
@ -372,7 +378,7 @@ class SmqlToAR
|
||||||
raise_unless col.exist_in? || SmqlToAR.model_of( col.last_model, col.col), NonExistingSelectableError.new( col)
|
raise_unless col.exist_in? || SmqlToAR.model_of( col.last_model, col.col), NonExistingSelectableError.new( col)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build builder, table
|
def select_build builder, table
|
||||||
@cols.each do |col|
|
@cols.each do |col|
|
||||||
if col.exist_in?
|
if col.exist_in?
|
||||||
col.joins builder, table
|
col.joins builder, table
|
||||||
|
@ -384,6 +390,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias build select_build
|
||||||
end
|
end
|
||||||
|
|
||||||
class Functions < Condition
|
class Functions < Condition
|
||||||
|
@ -432,7 +439,7 @@ class SmqlToAR
|
||||||
super model, func, args
|
super model, func, args
|
||||||
end
|
end
|
||||||
|
|
||||||
def build builder, table
|
def order_build builder, table
|
||||||
return if @args.blank?
|
return if @args.blank?
|
||||||
@args.each do |o|
|
@args.each do |o|
|
||||||
col, o = o
|
col, o = o
|
||||||
|
@ -442,26 +449,29 @@ class SmqlToAR
|
||||||
builder.order t, col.col, o
|
builder.order t, col.col, o
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
alias build order_build
|
||||||
end
|
end
|
||||||
|
|
||||||
class Limit < Function
|
class Limit < Function
|
||||||
Name = :limit
|
Name = :limit
|
||||||
Expected = [Fixnum]
|
Expected = [Fixnum]
|
||||||
|
|
||||||
def build builder, table
|
def limit_build builder, table
|
||||||
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
||||||
builder.limit = Array.wrap(@args).first.to_i
|
builder.limit = Array.wrap(@args).first.to_i
|
||||||
end
|
end
|
||||||
|
alias build limit_build
|
||||||
end
|
end
|
||||||
|
|
||||||
class Offset < Function
|
class Offset < Function
|
||||||
Name = :offset
|
Name = :offset
|
||||||
Expected = [Fixnum]
|
Expected = [Fixnum]
|
||||||
|
|
||||||
def build builder, table
|
def offset_build builder, table
|
||||||
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
||||||
builder.offset = Array.wrap(@args).first.to_i
|
builder.offset = Array.wrap(@args).first.to_i
|
||||||
end
|
end
|
||||||
|
alias build offset_build
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new model, col, val
|
def self.new model, col, val
|
||||||
|
|
|
@ -135,25 +135,25 @@ class SmqlToAR
|
||||||
case refl
|
case refl
|
||||||
when ActiveRecord::Reflection::ThroughReflection
|
when ActiveRecord::Reflection::ThroughReflection
|
||||||
through = refl.through_reflection
|
through = refl.through_reflection
|
||||||
throughtable = table[0...-1]+[Column::Col.new( through.name, table.last.as)]
|
through_table = table[0...-1]+[Column::Col.new( through.name, table.last.as)]
|
||||||
srctable = throughtable+[Column::Col.new( refl.source_reflection.name, table.last.as)]
|
srctable = through_table+[Column::Col.new( refl.source_reflection.name, table.last.as)]
|
||||||
@table_model[ srctable] = model
|
@table_model[ srctable] = model
|
||||||
@table_alias[ table] = @table_alias[ srctable]
|
@table_alias[ table] = @table_alias[ srctable]
|
||||||
join_ throughtable, through.klass, quote_table_name( through.table_name)
|
join_ through_table, through.klass, quote_table_name( through.table_name)
|
||||||
join_ srctable, refl.klass, query, throughtable
|
join_ srctable, refl.klass, query, through_table
|
||||||
when ActiveRecord::Reflection::AssociationReflection
|
when ActiveRecord::Reflection::AssociationReflection
|
||||||
case refl.macro
|
case refl.macro
|
||||||
when :has_many, :has_one
|
when :has_many, :has_one
|
||||||
@_joins += build_join query, pretable, t, premodel.primary_key, refl.primary_key_name
|
@_joins += build_join query, pretable, t, premodel.primary_key, refl.foreign_key
|
||||||
when :belongs_to
|
when :belongs_to
|
||||||
@_joins += build_join query, pretable, t, refl.primary_key_name, premodel.primary_key
|
@_joins += build_join query, pretable, t, refl.foreign_key, premodel.primary_key
|
||||||
when :has_and_belongs_to_many
|
when :has_and_belongs_to_many
|
||||||
jointable = [Column::Col.new(',')] + table
|
jointable = [Column::Col.new(',')] + table
|
||||||
@_joins += build_join refl.options[:join_table], pretable, @table_alias[jointable], premodel.primary_key, refl.primary_key_name
|
@_joins += build_join refl.options[:join_table], pretable, @table_alias[ jointable], premodel.primary_key, refl.foreign_key
|
||||||
@_joins += build_join query, jointable, t, refl.association_foreign_key, refl.association_primary_key
|
@_joins += build_join query, jointable, t, refl.association_foreign_key, refl.association_primary_key
|
||||||
else raise BuilderError, "Unkown reflection macro: #{refl.macro.inspect}"
|
else raise BuilderError, "Unkown reflection macro: #{refl.macro.inspect}"
|
||||||
end
|
end
|
||||||
else raise BuilderError, "Unkown reflection type: #{refl.class.name}"
|
else raise BuilderError, "Unkown reflection type: #{refl.class.name} #{refl.macro.inspect}"
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue