Flatpack
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.
Goals
- Provide alternate client implementations (use either supercomfy, cradle or nano)
- Use Travis-CI for continuous integration
Example
Defining a model
// Define a model with just the default view (getByType)flatpack;// Define a model with custom viewsflatpack;
Saving an object
// Create a documentvar customer = firstName: 'Nathan' lastName: 'Oehlman' company: 'Sidelab'customerdb = flatpack;// Save for the first timecustomerdb;
Getting and updating object
// Create a documentvar customerdb = flatpack;// Get the existing objectcustomerdb;
Using a view
By default, flatpack will create a default view that can access all documents of the type.
// Get all customer documentsvar customerdb = flatpack;customerdb;// Can also be accessed using the all aliascustomerdball {// etc};
Using a custom view is also very similar.
// Get all customer documents belonging to the Sidelab companyvar customerdb = flatpack;// An argumented view takes an opts object, that gets converted into Couch DB view parameters (so you can use startKey, endKey, etc)customerdb;