Class: Koine::SqlBuilder::Where

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/koine/sql_builder/where.rb

Instance Method Summary collapse

Constructor Details

#initialize(items = [], adapter:) ⇒ Where

Returns a new instance of Where.



8
9
10
11
# File 'lib/koine/sql_builder/where.rb', line 8

def initialize(items = [], adapter:)
  @adapter = adapter
  @items = items
end

Instance Method Details

#each(&block) ⇒ Object



22
23
24
# File 'lib/koine/sql_builder/where.rb', line 22

def each(&block)
  @items.each(&block)
end

#to_sObject



26
27
28
29
30
31
32
# File 'lib/koine/sql_builder/where.rb', line 26

def to_s
  unless items.empty?
    return "WHERE #{to_a.join(' AND ')}"
  end

  ''
end

#with_added_conditions(items = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/koine/sql_builder/where.rb', line 13

def with_added_conditions(items = {})
  items = Array(items).map do |item|
    @adapter.create_condition(item)
  end

  items = [@items, items].flatten
  self.class.new(items, adapter: @adapter)
end