opscode/sqerl — pull request #46 by seth (2014-04-27 20:55:41+00:00)
Title: Introduce sqerl_rec for convenient record <-> pg mapping

STATUS: provisional, putting out PR for comments on approach, etc

The sqerl_rec module makes it easier to define the queries and
functions to map a record to and from the db via sqerl.

The module defines a behaviour and assumes that each record has a
module of the same name implementing the behavior. Given this,
sqerl_rec and generate fetch, delete, insert, update, fetch_all, and
fetch_page prepared queries and you can then use the corresponding
fetch, delete, insert, update, fetch_all, and fetch_page functions in
the sqerl_rec module.

You get maximal convenience by using the exprecs parse transform in
your record module that implements the sqerl_rec behaviour, however,
it is not mandatory.

You can provide additional custom prepared queries for each record, or
avoid use of the default query generators entirely -- you'll need to
name queries and have parameters align if you still wish to make use
of the common db operation functions.

Assumptions:

- DB contains a pluralized version of record name. Currently done
simply as `TableName == RecordName ++ "s"`. Used by the query
generating helpers.

- The update function and query gen assumes an 'id' field and does
update by id.

Examples:

Look at the kitchen and cook modules in the test directory to see
what's required for simple cases. The corresponding schema is in
test/sqerl_rec_test_db_schema.sql. There is basic test coverage in
place for the kitchen module which demonstrates the db operation
helpers in the sqerl_rec module.