Class: Dorm::WhereDSL::FieldCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/dorm/query_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(field, table_name, dsl) ⇒ FieldCondition

Returns a new instance of FieldCondition.



363
364
365
366
367
# File 'lib/dorm/query_builder.rb', line 363

def initialize(field, table_name, dsl)
  @field = field
  @table_name = table_name
  @dsl = dsl
end

Instance Method Details

#eq(value) ⇒ Object



369
370
371
# File 'lib/dorm/query_builder.rb', line 369

def eq(value)
  Condition.new("#{@table_name}.#{@field} = #{@dsl.add_param(value)}", @dsl.params.dup)
end

#gt(value) ⇒ Object



377
378
379
# File 'lib/dorm/query_builder.rb', line 377

def gt(value)
  Condition.new("#{@table_name}.#{@field} > #{@dsl.add_param(value)}", @dsl.params.dup)
end

#gte(value) ⇒ Object



381
382
383
# File 'lib/dorm/query_builder.rb', line 381

def gte(value)
  Condition.new("#{@table_name}.#{@field} >= #{@dsl.add_param(value)}", @dsl.params.dup)
end

#in(values) ⇒ Object



397
398
399
400
# File 'lib/dorm/query_builder.rb', line 397

def in(values)
  placeholders = values.map { |v| @dsl.add_param(v) }.join(", ")
  Condition.new("#{@table_name}.#{@field} IN (#{placeholders})", @dsl.params.dup)
end

#like(pattern) ⇒ Object



393
394
395
# File 'lib/dorm/query_builder.rb', line 393

def like(pattern)
  Condition.new("#{@table_name}.#{@field} LIKE #{@dsl.add_param(pattern)}", @dsl.params.dup)
end

#lt(value) ⇒ Object



385
386
387
# File 'lib/dorm/query_builder.rb', line 385

def lt(value)
  Condition.new("#{@table_name}.#{@field} < #{@dsl.add_param(value)}", @dsl.params.dup)
end

#lte(value) ⇒ Object



389
390
391
# File 'lib/dorm/query_builder.rb', line 389

def lte(value)
  Condition.new("#{@table_name}.#{@field} <= #{@dsl.add_param(value)}", @dsl.params.dup)
end

#ne(value) ⇒ Object



373
374
375
# File 'lib/dorm/query_builder.rb', line 373

def ne(value)
  Condition.new("#{@table_name}.#{@field} != #{@dsl.add_param(value)}", @dsl.params.dup)
end

#not_nullObject



406
407
408
# File 'lib/dorm/query_builder.rb', line 406

def not_null
  Condition.new("#{@table_name}.#{@field} IS NOT NULL", @dsl.params.dup)
end

#nullObject



402
403
404
# File 'lib/dorm/query_builder.rb', line 402

def null
  Condition.new("#{@table_name}.#{@field} IS NULL", @dsl.params.dup)
end