Inspired by: CouchRest library for Ruby and the couchdb-python library.
- Specify a server:
$server = new SetteeServer('http://127.0.0.1:5984');
- Database API
- Create a database:
$ret = $server->create_db('irakli_test');
- Drop a database:
$ret = $server->drop_db('irakli_test');
- List all databases:
$ret = $server->list_dbs();
- Get a database object
$db = $server->get_db('irakli_test');
- Create a database:
- Document API
- Create/Update a document:
$ret = $db->save($doc);
- Retrieve a document:
$db_doc = $db->get($id);
- Determine the latest revision_id for a document:
$rev = $db->get_rev($id);
- Delete a document:
$db_doc = $db->delete($doc);
- Create/Update a document:
- Attachments API
- Add content as attachment:
$db->add_attachment($doc, "foo.txt", "Some text that will be base64 encoded", "text/plain");
- Add a file path to be attached:
$db->add_attachment_file($doc, "foo.pdf", $file_path, "application/pdf");
- Add a file path to be attached (mime-type is auto-detected):
$db->add_attachment_file($doc, "foo.pdf", $file_path);
- Full attachment saving example:
$doc = new stdClass();
$doc→id = “attachment_doc”;
$file_path = dirname(_FILE__) . “/resources/couch-logo.pdf”;
$this→db→add_attachment_file($doc, “foo.pdf”, $file_path, “application/pdf”);
$db_doc = $this→db→save($doc); - ATTENTION: there is no “load_attachments” method, because when you load a document, all its attachments get loaded with it, as well.
- Add content as attachment:
- Views API
- Create a new view or save a view:
$view = $db->save_view("some_design_document_id", "a_view_name", $map_src);
$view = $db->save_view("some_design_document_id", "a_view_name", $map_src, $reduce_src);
- Get a view (run query and get results):
$view = $db->get_view("some_design_document_id", "a_view_name");
- Parametrized view:
$view = $db->get_view("some_design_document_id", "a_view_name", "2009/02/17 21:13:39");
- Parametrized view with key range:
$view = $db->get_view("some_design_document_id", "a_view_name", array("2009/01/30 18:04:11", "2009/02/17 21:13:39"));
- Parametrized view with key range, ordered descending:
$view = $db->get_view("some_design_document_id", "a_view_name", array("2009/01/30 18:04:11", "2009/02/17 21:13:39"), true);
- Create a new view or save a view:
- PHP 5.2 or newer
- PHP 5.3 or newer. With PHP 5.2 following functionality will not work:
- Some unit-tests
- Mime type auto-detection.
- pecl_http