Class: Oplogjam::Operators::IntermediateIndex
Instance Attribute Summary
Attributes inherited from Intermediate
#path, #tree
Instance Method Summary
collapse
#initialize, #nodes, #populate, #populate_field, #populate_index, #set, #set_field, #set_index
Instance Method Details
#index ⇒ Object
38
39
40
|
# File 'lib/oplogjam/operators/intermediate_index.rb', line 38
def index
Integer(path.last, 10)
end
|
#parent_path ⇒ Object
34
35
36
|
# File 'lib/oplogjam/operators/intermediate_index.rb', line 34
def parent_path
path[0...-1]
end
|
#update(column) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/oplogjam/operators/intermediate_index.rb', line 6
def update(column)
filled_array_column = (0...index).inject(column) { |subject, i|
prior_path = parent_path + [i.to_s]
subject.set(prior_path, Sequel.function(:coalesce, column[prior_path], NULL))
}
populated_column = Sequel.pg_jsonb_op(
Sequel.case(
{
ARRAY_TYPE => filled_array_column.set(path, Sequel.function(:coalesce, filled_array_column[path], EMPTY_OBJECT))
},
column.set(path, Sequel.function(:coalesce, column[path], EMPTY_OBJECT)),
column[parent_path].typeof
)
)
nodes.inject(populated_column, &UPDATE_COLUMN)
end
|