Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release 0.0.8 - 16/03/2010

sfCouchPlugin

Installation

To install the plugin for a symfony project, the usual process is to use the symfony command line.
You have to add the alpha option as long as this plugin not stable.

$ symfony plugin:install -s alpha sfCouchPlugin

Alternatively, if you don't have PEAR installed, you can download the latest package attached to
this plugin's wiki page and extract it under your project's plugins/ directory. Make sure the
plugin is enabled in your project's /config/ProjectConfiguration.class.php if you install it
manually!

$this->enablePlugins('sfCouchPlugin');

Clear the cache to enable the autoloading to find the new classes:

$ php symfony cc

Copy the file CouchDB.yml and the folder CouchDB from the plugin's config folder to the project's
config-folder (/config)

Configuration

Edit the /config/CouchDB.yml for your CouchDB installation.

Creating documents

To create a new CouchDB document you can just instanciate a sfCouchDocument, set some key/value pairs
and save it.

You can also create a document with an own id (instead of the autogenerated uuid)

$newDoc = new sfCouchDocument('mySuperId');

If a document with this ID exists, it's fetched from the CouchDB and the property
newDoc->newDocument is set to false. That's the way to get a single document by ID from the db.

Files can be attached to a document with:

$newDoc->attachFile($filePath, $fileName, $mimeType);

Only the first parameter is mandatory. If no fileName is given, the Name is derived
from the file itself. If no mimetype is given it'll be 'application/octet-stream'.

Attachments can be loaded from a CouchDB document with:

$tempFilePath = $newDoc->getFile($fileName);

The file will be put in the webservers temp folder and the method returns the path of the
temp file.

If you want to have some more specialized documents just create a new model class that
inherits sfCouchDocument.

class mySpecialDocument extends sfCouchDocument
{
// use this property to define keys that have to be set
protected $requiredProperties = array('type', 'name');
...
}

Views

To create a view just put a javascript file in the folder /config/CouchDB
that is named VIEWNAME_map.js. If you also need a reduce function create another
file named named VIEWNAME_reduce.js. There's a very simple example 'all_map.js' in
the distribution.

Note: In production env the views don't get updated automatically. If you change a
javascript you have to call the task couch:refreshViews.

$ php symfony couch:refreshViews

Then call the view with sfCouchView::query($viewName, [$options]). The first parameter
ist the VIEWNAME from the javascript files. The optional second parameter is an array
with the CouchDB query options See CouchDB wiki.