Module: Tsuga::Adapter::Sequel::Base::DatasetMethods

Defined in:
lib/tsuga/adapter/sequel/base.rb

Instance Method Summary collapse

Instance Method Details

#collect_idsObject



43
44
45
# File 'lib/tsuga/adapter/sequel/base.rb', line 43

def collect_ids
  map(:id)
end

#delete_allObject



39
40
41
# File 'lib/tsuga/adapter/sequel/base.rb', line 39

def delete_all
  where.delete
end

#find_by_id(id) ⇒ Object



35
36
37
# File 'lib/tsuga/adapter/sequel/base.rb', line 35

def find_by_id(id)
  self[id]
end

#find_eachObject



47
48
49
50
51
52
53
54
# File 'lib/tsuga/adapter/sequel/base.rb', line 47

def find_each
  # TODO: pagination would be nice to have here, but seems not to
  # work out-of-the-box with Sequel
  # where.extension(:pagination).each_page(2000) do |page|
  #   page.each { |r| yield r }
  # end
  all.each { |r| yield r }
end

#mass_create(new_records) ⇒ Object



25
26
27
# File 'lib/tsuga/adapter/sequel/base.rb', line 25

def mass_create(new_records)
  multi_insert(new_records.map(&:to_hash))
end

#mass_update(records) ⇒ Object



29
30
31
32
33
# File 'lib/tsuga/adapter/sequel/base.rb', line 29

def mass_update(records)
  db.transaction do
    records.each(&:save)
  end
end