fix reduce
[disclosr.git] / couchdb / settee / README.textile
Maxious 1 Inspired by: "CouchRest library for Ruby":http://jchrisa.net/drl/_design/sofa/_list/post/post-page?startkey=%5B%22couchrest__restful_ruby_client_%22%5D and the "couchdb-python":http://packages.python.org/CouchDB/client.html#document library.
2
3 h3. Server Functions
4
5 # Specify a server:
6 @$server = new SetteeServer('http://127.0.0.1:5984');@
7 # Database API
8 ## Create a database:
9 @$ret = $server->create_db('irakli_test');@
10 ## Drop a database:
11 @$ret = $server->drop_db('irakli_test');@
12 ## List all databases:
13 @$ret = $server->list_dbs();@
14 ## Get a database object
15 @$db = $server->get_db('irakli_test');@
16 # Document API
17 ## Create/Update a document:
18 @$ret = $db->save($doc);@
19 ## Retrieve a document:
20 @$db_doc = $db->get($id);@
21 ## Determine the latest revision_id for a document:
22 @$rev = $db->get_rev($id);@
23 ## Delete a document:
24 @$db_doc = $db->delete($doc);@
25 # Attachments API
26 ## Add content as attachment:
27 @$db->add_attachment($doc, "foo.txt", "Some text that will be base64 encoded", "text/plain");@
28 ## Add a file path to be attached:
29 @$db->add_attachment_file($doc, "foo.pdf", $file_path, "application/pdf");@
30 ## Add a file path to be attached (mime-type is auto-detected):
31 @$db->add_attachment_file($doc, "foo.pdf", $file_path);@
32 ## Full attachment saving example:
33 $doc = new stdClass();
34 $doc->_id = "attachment_doc";
35 $file_path = dirname(__FILE__) . "/resources/couch-logo.pdf";
36 $this->db->add_attachment_file($doc, "foo.pdf", $file_path, "application/pdf");
37 $db_doc = $this->db->save($doc);
38 ## ATTENTION: there is no "load_attachments" method, because when you load a document, all its attachments get loaded with it, as well.
39 # Views API
40 ## Create a new view or save a view:
41 @$view = $db->save_view("some_design_document_id", "a_view_name", $map_src);@
42 @$view = $db->save_view("some_design_document_id", "a_view_name", $map_src, $reduce_src);@
43 ## Get a view (run query and get results):
44 @$view = $db->get_view("some_design_document_id", "a_view_name");@
45 ## Parametrized view:
46 @$view = $db->get_view("some_design_document_id", "a_view_name", "2009/02/17 21:13:39");@
47 ## Parametrized view with key range:
48 @$view = $db->get_view("some_design_document_id", "a_view_name", array("2009/01/30 18:04:11", "2009/02/17 21:13:39"));@
49 ## Parametrized view with key range, ordered descending:
50 @$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);@
51
52
53 h3. Requirements
54 # PHP 5.2 or newer
55
56 h3. Recommended
57 # PHP 5.3 or newer. With PHP 5.2 following functionality will not work:
58 ## Some unit-tests
59 ## Mime type auto-detection.
60 # pecl_http