Project

wal

0.0
The project is in a healthy, maintained state
Hook up into Postgres WAL log
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Wal

Easily hook into Postgres WAL event log from your Rails app.

Proper documentation TBD

Examples

Watch for model changes using the RecordWatcher DSL

class ProductAvailabilityWatcher < Wal::RecordWatcher
  on_save Product, changed: %w[price] do |event|
    recalculate_inventory_price(event.primary_key, event.new["price"])
  end

  on_destroy Product do |event|
    clear_product_inventory(event.primary_key)
  end

  on_save Sales, changed: %w[status] do |event|
    recalculate_inventory_quantity(event.primary_key)
  end

  def recalculate_inventory_price(product_id, new_price)
    # ...
  end

  def clear_product_inventory(product_id)
    # ...
  end

  def recalculate_inventory_quantity(sales_id)
    # ...
  end
end

Basic watcher implementation

class LogWatcher
  include Wal::Watcher

  def on_event(event)
    puts "Wal event received #{event}"
  end
end