digital-fabric / extralite

Ruby on SQLite
http://www.rubydoc.info/gems/extralite
MIT License
255 stars 8 forks source link

Add API for changesets #58

Closed noteflakes closed 10 months ago

noteflakes commented 10 months ago

Using the bundled SQLite session extension, changesets can be generated that track changes to data, which can then be represented in a blob. Here's how the Extralite API might look:


changeset = db.track_changes(:foo, :bar) do |cs|
  cs.attach(:baz) # attach more tables

  db << "insert into foo values (1, 2, 3)"
end

# iterate through changes
changeset.each { |c| p c }

# get all changes
changeset.to_a

# get changeset blob
changeset.to_blob

# get patchset
changeset.to_blob_patchset

# load from blob
changeset = Extralite::Changeset.new(blob)

# invert
changeset.invert(db)

# apply to DB
changeset.apply(db)