Class: Bmg::Sequel::Relation

Inherits:
Object
  • Object
show all
Includes:
Relation
Defined in:
lib/bmg/sequel/relation.rb

Constant Summary

Constants included from Algebra

Algebra::METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Relation

#debug, empty, #empty?, new, #one, #one_or_nil, #to_json, #visit, #ys_by_x

Methods included from Algebra

#allbut, #autosummarize, #autowrap, #constants, #extend, #image, #matching, #project, #rename, #restrict, #spied, #union, #unspied

Constructor Details

#initialize(type, dataset) ⇒ Relation

Returns a new instance of Relation.



6
7
8
9
# File 'lib/bmg/sequel/relation.rb', line 6

def initialize(type, dataset)
  @type = type
  @dataset = dataset
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/bmg/sequel/relation.rb', line 10

def type
  @type
end

Instance Method Details

#deleteObject



22
23
24
# File 'lib/bmg/sequel/relation.rb', line 22

def delete
  dataset.delete
end

#each(&bl) ⇒ Object



18
19
20
# File 'lib/bmg/sequel/relation.rb', line 18

def each(&bl)
  @dataset.each(&bl)
end

#insert(arg) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bmg/sequel/relation.rb', line 26

def insert(arg)
  case arg
  when Hash then
    dataset.insert(arg.merge(type.predicate.constants))
  when Enumerable then
    dataset.multi_insert(arg.map { |x|
      x.merge(type.predicate.constants)
    })
  else
    dataset.insert(arg.merge(type.predicate.constants))
  end
end

#to_astObject



43
44
45
# File 'lib/bmg/sequel/relation.rb', line 43

def to_ast
  [:sequel, dataset.sql]
end

#to_sObject Also known as: inspect



47
48
49
# File 'lib/bmg/sequel/relation.rb', line 47

def to_s
  "(sequel #{dataset.sql})"
end

#update(arg) ⇒ Object



39
40
41
# File 'lib/bmg/sequel/relation.rb', line 39

def update(arg)
  dataset.update(arg)
end