incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filippo Fadda <filippo.fa...@programmazione.it>
Subject A console application made with ElephantOnCouch
Date Thu, 25 Jul 2013 15:18:58 GMT
I'm in the middle of rebuilding the Programmazione.it platform using Apache + PHP + CouchDB
+ Redis + Phalcon + ElephantOnCouch + EOCSvr. To import data from MySQL I wrote a console
application based on Symfony Console component, using ElephantOnCouch client library.
The code I have written for this console could be a part of a large project to expose all
CouchDB APIs from command line: ElephantOnCouch Console. Watch for example the query command.
:-)
Let me show you something:

fff@macpro:~$ 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.
  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.


fff@macpro:~$ pit about
[server]

Welcome
CouchDB 1.3.1

[client]

ElephantOnCouch 0.2.4
Transport Method: PHP Sockets
Protocol Version: HTTP/1.1

[database]

Name: programmazione
File Opened Since: 0 days, 18 hours, 24 minutes, 28 seconds
Disk Size (Bytes): 134254705
Data Size (Bytes): 39989542
Disk Format Version: 6
Compaction: inactive
Number of Documents: 21535
Number of Deleted Documents: 0
Number of Updates: 21535
Number of Purge Operations: 0
Number of Committed Updates: 21535


fff@macpro:~$ pit help query
Usage:
 query [--key="..."] [--limit="..."] [--group-results] [--group-level="..."] [--do-not-reduce]
[--include-docs] [--exclude-results] [--exclude-endkey] [--reverse-order] [--skip="..."] [--include-conflicts]
[--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.

Options:
 --key                 Returns only documents that match the specified key.
 --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.
 --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"}
]}

Isn't it cool?
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message