evanmiller/boss_db — pull request #133 by brigadier (2013-11-19 18:44:33+00:00)
Title: query subset of model properties as proplists

boss_db.find(...) always returns list of models with all model data. Sometimes it results in excessive use of server resources, especially of RAM and HDD I/O throughput. For example, if we have a number of large blog posts and want to show a list of these posts (we need just Post Title and Post ID) in the admin panel, boss_db always reads all the posts' data from DB, including posts contents.

This patch adds an ability to return a subset of fields as proplists. At the moment it works for MySQL and PgSQL adapters only (and only postgres adapter was tested), and for find() function which returns list of results only. Doesn't work for find_first, find_last and find(ID).

find(...) now accepts a new option: {capture, model|proplist|{proplist, Fields::list()}. If there's no such option {capture, model} is assumed for backward compatibility.

For example:
boss_db:find(sometable, [{id, equals,"sometable-2"}], [{capture, {proplist, [name, id}}]).

{capture, model} makes find() to return standard list of boss_db models
{capture, {proplist, Fields}} makes find() to return list of proplists like [{FieldName1, FieldValue1}... {FieldNameN, FieldValueN}] for each field in Fields list. if Fields is empty, all fields are returned.
{capture, proplist} - same as above with all fields returned.

I'm not sure how this work with caching though, likely it is to early to merge it into master.
It is just an idea.