public
Description: Database enforced timestamps, immutable columns, and counter/sum caches
Homepage:
Clone URL: git://github.com/jeremyevans/sequel_postgresql_triggers.git
name age message
file .gitignore Fri Dec 12 11:19:59 -0800 2008 Initial commit [jeremyevans]
file LICENSE Tue Jun 02 16:00:57 -0700 2009 Fix usage on Sequel 2.12.0+; Bump version to 1.... [jeremyevans]
file README Fri Dec 12 16:30:49 -0800 2008 Small README fix [jeremyevans]
file Rakefile Fri Dec 12 11:19:59 -0800 2008 Initial commit [jeremyevans]
directory lib/ Tue Jun 02 16:00:57 -0700 2009 Fix usage on Sequel 2.12.0+; Bump version to 1.... [jeremyevans]
file sequel_postgresql_triggers.gemspec Tue Jun 02 16:00:57 -0700 2009 Fix usage on Sequel 2.12.0+; Bump version to 1.... [jeremyevans]
directory spec/ Sun Oct 11 15:47:13 -0700 2009 Change the default user for the specs [jeremyevans]
README
= Sequel PostgreSQL Triggers

Sequel PostgreSQL Triggers is a small enhancement to Sequel allowing
a user to easily handle the following types of columns:

* Timestamp Columns (Created At/Updated At)
* Counter/Sum Caches
* Immutable Columns

It handles these internally to the database via triggers, so even if
other applications access the database (without using Sequel), things
will still work (unless the database superuser disables triggers).

To use any of these methods, you have to add the plpgsql procedural
language to PostgreSQL, which you can do with:

  DB.create_language(:plpgsql)

== Triggers

=== Created At Columns - pgt_created_at

pgt_created_at takes the table and column given and makes it so that
upon insertion, the column is set to the CURRENT_TIMESTAMP, and that
upon update, the column's value is always set to the previous value.
This is sort of like an immutable column, but it doesn't bring up an
error if you try to change it, it just ignores it.

=== Updated At Columns - pgt_updated_at

Similar to pgt_created_at, takes a table and column and makes it so
that upon insertion, the column is set to CURRENT_TIMESTAMP. It
differs that upon update, the column is also set to CURRENT_TIMESTAMP.

=== Counter Cache - pgt_counter_cache

This takes quite a few arguments (see the RDoc) and sets up a
counter cache so that when the counted table is inserted to
or deleted from, records in the main table are updated with the
count of the corresponding records in the counted table.

=== Sum Cache - pgt_sum_cache

Similar to pgt_counter_cache, except instead of storing a count
of records in the main table, it stores the sum on one of the
columns in summed table.

=== Immutable Columns - pgt_immutable

This takes a table name and one or more column names, and adds
an update trigger that raises an exception if you try to modify
the value of any of the columns.

== License

This library is released under the MIT License.  See the LICENSE file for details.

== Author

Jeremy Evans <code@jeremyevans.net>