ElephantOnCouch is a CouchDB client written in PHP, using both cURL or raw
sockets (default method, handle chunk responses, persistent connection, etc.)
as transport layers. In ElephantOnCouch you don't save JSON documents, but
objects. You can store every instance of any Doc subclass you have defined, or
you can implement the IDoc interface or use the trait TDoc in your classes so
they become persistent. When you retrieve a document from CouchDB using
ElephantOnCouch you obtain an object of the class you have previously stored.
Your objects are translated in persistent documents so you can write easily
object oriented software.
ElephantOnCouch comes with a PHP Query Server (EOCSvr), giving you the ability
to write map/reduce and other handlers in PHP. ElephantOnCouch is not just a
REST client to use the CouchDB APIs, but it's a complete CouchDB client with
methods for all the CouchDB APIs and options. You don't need to know when use
POST or PUT or GET or deal with CouchDB documentation, you just use the
ElephantOnCouch methods. The exhaustive documentation can be generated using
Doxygen.
There is nothing like ElephantOnCouch and you can't find any description
because it's still a work in progress. I still have to implement some handlers,
adding caching, etc. But it works. Feel free to contribute: writing tests, a
tutorial, making a logo, etc.
Here an example of a query:
// Establishes the connection.
$couch = new Couch("127.0.0.1:5984", "foo", "bar");
// Selects database.
$couch->selectDb("test");
// Sets the options.
$opts = new ViewQueryOpts();
$opts->doNotReduce()->setLimit(30)->reverseOrderOfResults()->setStartKey(['blog',
new \stdClass()])->setEndKey(['blog']);
// Queries the view.
$rows = $couch->queryView("posts", "newestPerSection", NULL, $opts)['rows'];
I have also created a command line console (like mysql), that let you interact
directly with CouchDB. Not all the commands are implemented, but I will release
it as part of the ElephantOnCouch suite soon as I can.
fff@macpro:~/Dropbox/Progetti/pit-press$ pit
PitPress Console version 0.1.0
Usage:
[options] command [arguments]
Options:
--help -h Display this help message.
--quiet -q Do not output any message.
--verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal
output, 2 for more verbose output and 3 for debug
--version -V Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction -n Do not ask any interactive question.
Available commands:
about Displays information about PitPress, like version, database, etc.
cleanup Removes all outdated view indexes.
commit Makes sure all uncommited database changes are written and
synchronized to the disk.
compact Starts a compaction for the current selected database.
create Creates a new database.
delete Deletes the PitPress database.
generate Generates fake accessory documents per post.
help Displays help for a command
import Imports into CouchDB the data from Programmazione.it v6.4 MySQL
database.
init Initializes the PitPress database, adding the required design
documents.
install Executes the following commands: create, prepare, import all, init
all.
list Lists commands
prepare Prepares Programmazione.it v6.4 MySQL database to be imported.
query Query a view and outputs the result.
restore Restores Programmazione.it v6.4 MySQL database.
status Gets PitPress list of active tasks.
fff@macpro:~/Dropbox/Progetti/pit-press$ pit help query
Usage:
query [--key="..."] [--startkey="..."] [--endkey="..."]
[--startkey-docid="..."] [--endkey-docid="..."] [--limit="..."]
[--group-results] [--group-level="..."] [--do-not-reduce] [--include-docs]
[--exclude-results] [--exclude-endkey] [--reverse-order] [--skip="..."]
[--include-conflicts] [--include-missing-keys] [--map="..."] [--reduce="..."]
[--language="..."] design-doc/view-name [keys1] ... [keysN]
Arguments:
design-doc/view-name The design document name followed by the view you want
query. In case of a temporary view,
use: _temp_view --map=map.txt
--reduce=reduce.txt. The files map.txt and reduce.txt must contains the map and
reduce functions implementation.
keys Used to retrieve just the view rows matching that set
of keys. Rows are returned in the order of the specified
keys. Combining this feature with --include-docs
results in the so-called multi-document-fetch feature.
In case yours keys are string, they must be
quoted with double quotes and escaped, like \"firstkey\", \"secondkey\".
Options:
--key Returns only documents that match the specified key.
In case the key is a string, it must be quoted
with double quotes and escaped, like --key=\"mykey\".
--startkey Defines the first key to be included in the range.
In case the key is a string, it must be quoted
with double quotes and escaped, like --startkey=\"mykey\".
To provide a complex key, instead, you must use
--startkey=[\"book\",{}]. The {} symbol is a wildcard used in
JavaScript to create an empty object.
Don't put a space between the values of your
complex key, because the console will consider them like new arguments.
Unfortunately, there is known bug that don't let
you write something like --startkey=[\"my book\",{}].
--endkey Defines the last key to be included in the range.
In case the key is a string, it must be quoted
with double quotes and escaped, like --endkey=\"mykey\".
--startkey-docid Sets the ID of the document with which to start the
range.
--endkey-docid Sets the ID of the document with which to end the
range.
--limit Limit the number of results.
--group-results Results should be grouped.
--group-level Level at which documents should be grouped.
--do-not-reduce Even is a reduce function is defined for the view,
doesn't call it.
--include-docs Includes documents in the output.
--exclude-results Don't get any data, but all meta-data for this View.
The number of documents in this View for example.
--exclude-endkey Tells CouchDB to not include end key in the result.
--reverse-order Reverses order of results.
--skip Skips the defined number of documents.
--include-conflicts Includes conflict documents.
--include-missing-keys Includes all the rows, even if a match for a key is
not found.
--map Load map function from this file. To be used with
_temp_view only, ignored otherwise.
--reduce Load reduce function from this file. To be used with
_temp_view only, ignored otherwise.
--language The language used to implement the map and reduce
functions. If no specified, PHP assumed.
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal
output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
fff@macpro:~$ pit query index/latest --do-not-reduce --limit=30 --reverse-order
{"total_rows":21534,"offset":0,"rows":[
{"id":"76b646a4-7797-4852-f6f7-425628abdc3b","key":"2013-03-15
13:00:26","value":"76b646a4-7797-4852-f6f7-425628abdc3b"},
{"id":"c88803a2-84a8-4ef7-ad14-11fc16068992","key":"2013-03-05
15:55:01","value":"c88803a2-84a8-4ef7-ad14-11fc16068992"},
{"id":"ba427ec2-6a97-47c5-e94e-ffffcc918a1a","key":"2013-02-25
02:08:23","value":"ba427ec2-6a97-47c5-e94e-ffffcc918a1a"},
{"id":"2e3b9ad3-d0fa-434a-e8f9-28f7d0c2fe0f","key":"2013-02-25
01:41:21","value":"2e3b9ad3-d0fa-434a-e8f9-28f7d0c2fe0f"},
{"id":"f6b85de6-ffeb-49cc-c421-9fa2a2db898f","key":"2013-02-19
14:45:22","value":"f6b85de6-ffeb-49cc-c421-9fa2a2db898f"},
{"id":"5de4713f-405f-4bd9-dd1b-35836416affe","key":"2013-02-11
12:06:06","value":"5de4713f-405f-4bd9-dd1b-35836416affe"},
{"id":"fa8546c7-73be-4ff0-c04a-a78f877b5351","key":"2013-02-05
16:57:56","value":"fa8546c7-73be-4ff0-c04a-a78f877b5351"},
{"id":"552aae3d-60c6-4942-9f78-2ae349ebf9aa","key":"2013-01-30
13:20:25","value":"552aae3d-60c6-4942-9f78-2ae349ebf9aa"},
{"id":"bce6118c-8401-4043-eade-8267c406f909","key":"2013-01-24
05:43:21","value":"bce6118c-8401-4043-eade-8267c406f909"},
{"id":"555c87df-3a0f-4886-bb71-49437b3d76c0","key":"2012-12-23
20:03:14","value":"555c87df-3a0f-4886-bb71-49437b3d76c0"},
{"id":"0c1295d1-b701-41e6-b040-0e9a31671f91","key":"2012-12-19
19:36:16","value":"0c1295d1-b701-41e6-b040-0e9a31671f91"},
{"id":"8d2ceb67-449f-4cb7-dd38-6c752a422b77","key":"2012-12-17
14:37:57","value":"8d2ceb67-449f-4cb7-dd38-6c752a422b77"},
{"id":"659eece4-5f01-489a-98c9-3fb7409f8944","key":"2012-12-07
14:46:27","value":"659eece4-5f01-489a-98c9-3fb7409f8944"},
{"id":"fb0ff625-b6d6-4c69-8a24-5c27a3cda24e","key":"2012-12-03
12:07:10","value":"fb0ff625-b6d6-4c69-8a24-5c27a3cda24e"},
{"id":"58666125-ec14-4838-d00b-9dbd083154bf","key":"2012-12-03
11:58:57","value":"58666125-ec14-4838-d00b-9dbd083154bf"},
{"id":"e4a8fb99-0a14-48b0-d17b-6baf69ab8639","key":"2012-11-27
16:40:42","value":"e4a8fb99-0a14-48b0-d17b-6baf69ab8639"},
{"id":"2fe1d8c0-1503-4cdb-9766-43a48729a340","key":"2012-11-26
10:15:46","value":"2fe1d8c0-1503-4cdb-9766-43a48729a340"},
{"id":"ce81793f-a109-4596-b06d-6c6de8394197","key":"2012-11-26
10:11:53","value":"ce81793f-a109-4596-b06d-6c6de8394197"},
{"id":"97b25567-b67b-4a94-a58e-7d9c8c2f299d","key":"2012-11-26
09:54:12","value":"97b25567-b67b-4a94-a58e-7d9c8c2f299d"},
{"id":"e428abe4-be46-4d7f-fc6e-3103c15412f6","key":"2012-11-15
01:02:24","value":"e428abe4-be46-4d7f-fc6e-3103c15412f6"},
{"id":"cfd21d1e-03f8-49b9-9e22-26b897b4d977","key":"2012-11-15
00:59:26","value":"cfd21d1e-03f8-49b9-9e22-26b897b4d977"},
{"id":"80552941-2fbd-4a22-e8cf-176c394f90db","key":"2012-11-05
16:16:08","value":"80552941-2fbd-4a22-e8cf-176c394f90db"},
{"id":"c7664789-db86-4950-80eb-f7d040faa7ae","key":"2012-11-01
18:05:05","value":"c7664789-db86-4950-80eb-f7d040faa7ae"},
{"id":"fa81665c-dc2f-40bb-bf3d-de888704d3e8","key":"2012-10-30
01:06:40","value":"fa81665c-dc2f-40bb-bf3d-de888704d3e8"},
{"id":"4924c23f-6bc5-4eca-aba8-5dc4605e2beb","key":"2012-10-25
03:30:29","value":"4924c23f-6bc5-4eca-aba8-5dc4605e2beb"},
{"id":"a7942413-91ef-4fa9-8da8-ca376fc60162","key":"2012-10-25
03:28:22","value":"a7942413-91ef-4fa9-8da8-ca376fc60162"},
{"id":"fdfea671-eb01-4827-c84d-0b3a00b67212","key":"2012-10-22
15:31:47","value":"fdfea671-eb01-4827-c84d-0b3a00b67212"},
{"id":"b86e458e-2fa0-4648-9c60-c5be0120fd1f","key":"2012-10-17
16:33:27","value":"b86e458e-2fa0-4648-9c60-c5be0120fd1f"},
{"id":"3aacf6a1-30f2-4b79-d391-89db75bfa0cd","key":"2012-10-17
16:25:32","value":"3aacf6a1-30f2-4b79-d391-89db75bfa0cd"},
{"id":"82e1412e-2c46-4d06-d6d9-442a2fe0669c","key":"2012-10-11
17:07:41","value":"82e1412e-2c46-4d06-d6d9-442a2fe0669c"}
]}
On Nov 12, 2013, at 4:41 AM, Mark Deibert wrote:
> What is ElephantOnCouch?!?! There is zero info on the github. I'm very
> intrigued...