Module: Alf::Sequel::Connection::UpdateMethods

Included in:
Alf::Sequel::Connection
Defined in:
lib/alf/sequel/connection/update_methods.rb

Instance Method Summary collapse

Instance Method Details

#delete(name, predicate) ⇒ Object

Delete from the relvar called ‘name`



27
28
29
# File 'lib/alf/sequel/connection/update_methods.rb', line 27

def delete(name, predicate)
  delete_uow(name, predicate).run
end

#in_transaction(*args, &bl) ⇒ Object

Yields the block in a transaction



7
8
9
# File 'lib/alf/sequel/connection/update_methods.rb', line 7

def in_transaction(*args, &bl)
  sequel_db.transaction(*args, &bl)
end

#insert(name, tuples) ⇒ Object

Inserts ‘tuples` in the relvar called `name`



22
23
24
# File 'lib/alf/sequel/connection/update_methods.rb', line 22

def insert(name, tuples)
  insert_uow(name, tuples).run
end

#lock(name, mode, &bl) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/alf/sequel/connection/update_methods.rb', line 11

def lock(name, mode, &bl)
  with_dataset(name){|ds|
    if ds.respond_to?(:lock)
      ds.lock(mode.to_s.upcase, &bl)
    else
      yield
    end
  }
end

#update(name, updating, predicate) ⇒ Object

Updates the relvar called ‘name`



32
33
34
# File 'lib/alf/sequel/connection/update_methods.rb', line 32

def update(name, updating, predicate)
  update_uow(name, updating, predicate).run
end

#with_dataset(name, predicate = nil) {|ds| ... } ⇒ Object

Yields:

  • (ds)


38
39
40
41
42
43
44
# File 'lib/alf/sequel/connection/update_methods.rb', line 38

def with_dataset(name, predicate = nil)
  ds = name.is_a?(Symbol) ? sequel_db[name] : name
  if predicate && !predicate.tautology?
    ds = ds.where(Translator.new(sequel_db).call(predicate.sexpr))
  end
  yield(ds) if block_given?
end