Class: Oplogjam::Operators::IndexAssignment
Instance Attribute Summary
Attributes inherited from Assignment
#path, #value
Instance Method Summary
collapse
Methods inherited from Assignment
#initialize
Instance Method Details
#index ⇒ Object
30
31
32
|
# File 'lib/oplogjam/operators/index_assignment.rb', line 30
def index
Integer(path.last, 10)
end
|
#parent_path ⇒ Object
34
35
36
|
# File 'lib/oplogjam/operators/index_assignment.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
|
# File 'lib/oplogjam/operators/index_assignment.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 },
column,
column[parent_path].typeof
)
)
populated_column.set(path, value.to_json)
end
|