github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jeremyevans / sequel_postgresql_triggers

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Database enforced timestamps, immutable columns, and counter/sum caches — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Change the default user for the specs 
jeremyevans (author)
Sun Oct 11 15:47:13 -0700 2009
commit  5877eec77227ae540fca01d61aab6ded6eb34e4d
tree    aae05a12db5dffba3fad21cd8e5e5a68813c902c
parent  8aecd6d3502eea83d1820f9870049b43cd48a23f
sequel_postgresql_triggers /
name age
history
message
file .gitignore Loading commit data...
file LICENSE
file README
file Rakefile
directory lib/
file sequel_postgresql_triggers.gemspec
directory spec/
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>
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server