Simple mapping library for CouchDB
Flatpack provides some simple document modelling for CouchDB built on top of supercomfy CouchDB client. Flatpack will allow you to define a model, and will then create appropriate permanent views in CouchDB to allow for easy searching and retrieval of these documents, as well as creating a helper object which will allow you to easily manipulate documents of that type.
// Define a model with just the default view (getByType)flatpackdefinecouchurl db 'customer' null callback;// Define a model with custom viewsflatpackdefinecouchurl db 'customer' views: byName: 'firstName' 'lastName' callback;
// Create a documentvar customer = firstName: 'Nathan' lastName: 'Oehlman' company: 'Sidelab'customerdb = flatpackuse'customer';// Save for the first timecustomerdbsavecustomer// id is the id assigned by couch to the document;
// Create a documentvar customerdb = flatpackuse'customer';// Get the existing objectcustomerdbgetidif !err// Update the detailsobjectfirstName = 'Thomas';customerdbsaveobjectif !err// All ok!;;