class Oplogjam::Insert
Attributes
document[R]
h[R]
id[R]
namespace[R]
ns[R]
o[R]
ts[R]
Public Class Methods
from(bson)
click to toggle source
# File lib/oplogjam/insert.rb, line 7 def self.from(bson) h = bson.fetch(H) ts = bson.fetch(TS) ns = bson.fetch(NS) o = bson.fetch(O) new(h, ts, ns, o) rescue KeyError => e raise InvalidInsert, "missing field: #{e}" end
new(h, ts, ns, o)
click to toggle source
# File lib/oplogjam/insert.rb, line 18 def initialize(h, ts, ns, o) @h = Integer(h) @ts = Oplogjam::Timestamp(ts) @ns = String(ns) @o = Oplogjam::Document(o) end
Public Instance Methods
==(other)
click to toggle source
# File lib/oplogjam/insert.rb, line 33 def ==(other) return false unless other.is_a?(Insert) id == other.id end
apply(mapping)
click to toggle source
# File lib/oplogjam/insert.rb, line 39 def apply(mapping) table = mapping[namespace] return unless table row_id = Sequel.object_to_json(document.fetch(ID)) table .insert_conflict( target: :id, conflict_where: { deleted_at: nil }, update: { document: Sequel[:excluded][:document], updated_at: Time.now.utc } ) .insert( id: row_id, document: Sequel.pg_jsonb(document), created_at: Time.now.utc, updated_at: Time.now.utc ) end
timestamp()
click to toggle source
# File lib/oplogjam/insert.rb, line 29 def timestamp Time.at(ts.seconds, ts.increment) end