Permalink
Browse files

added stuff for temporary view #11

  • Loading branch information...
1 parent 5d54a44 commit 2c41e7fcbb31045a5251b2b1effd64fbd41c6e03 @stefanjudis committed Mar 19, 2013
Showing with 142 additions and 4 deletions.
  1. +81 −1 README.md
  2. +49 −2 lib/commands/databaseCommands.js
  3. +12 −1 lib/help/messages.js
View
@@ -669,6 +669,8 @@ connection ✩ [host] ✩ -
**! This command is supported by auto-completion for the document id !**
+**Example:**
+
```
database ✩ [databaseName] ✩ -> document doc1
@@ -746,9 +748,87 @@ committed_update_seq: 149
database ✩ [databaseName] ✩ ->
```
+### tmpView [map] [params|reduce] [reduce]
+
+**Description:** Retrieve a temporary view for given database.
+
+**Example:**
+
+```
+database ✩ [databaseName] ✩ -> tmpView 'function(doc) {emit(doc._id, doc);}'
+This databases exists of 10 document.
+Displayed result has an offset of 0.
+
+
+Response:
+-
+ id: 4be0aced2a9fba4d4514ceb56e007a04
+ key: 4be0aced2a9fba4d4514ceb56e007a04
+ value:
+ _id: 4be0aced2a9fba4d4514ceb56e007a04
+ _rev: 1-967a00dff5e02add41819138abb3284d
+-
+ id: id1
+ key: key1
+ value:
+ _id: id1
+ _rev: 6-841ea3bec41a1ccbf776591dda80e1f9
+ name: foo
+
+database ✩ [databaseName] ✩ ->
+```
+
+```
+database ✩ [databaseName] ✩ -> tmpView 'function(doc) {emit(doc._id, doc);}' limit=1
+This databases exists of 10 documents.
+Displayed result has an offset of 0.
+
+
+Response:
+-
+ id: 4be0aced2a9fba4d4514ceb56e007a04
+ key: 4be0aced2a9fba4d4514ceb56e007a04
+ value:
+ _id: 4be0aced2a9fba4d4514ceb56e007a04
+ _rev: 1-967a00dff5e02add41819138abb3284d
+
+database ✩ [databaseName] ✩ ->
+```
+
+```
+database ✩ [databaseName] ✩ -> tmpView 'function(doc) {emit(doc._id, doc);}' 'function(keys, values, rereduce){return sum()}'
+This databases exists of undefined documents.
+Displayed result has an offset of undefined.
+
+
+Response:
+-
+ key: null
+ value: 0
+
+database ✩ [databaseName] ✩ ->
+```
+
+```
+database ✩ [databaseName] ✩ -> tmpView 'function(doc) {emit(doc._id, doc);}' limit=1 'function(keys, values, rereduce){return sum()}'
+This databases exists of 10 documents.
+Displayed result has an offset of 0.
+
+
+Response:
+-
+ id: 4be0aced2a9fba4d4514ceb56e007a04
+ key: 4be0aced2a9fba4d4514ceb56e007a04
+ value:
+ _id: 4be0aced2a9fba4d4514ceb56e007a04
+ _rev: 1-967a00dff5e02add41819138abb3284d
+
+database ✩ [databaseName] ✩ ->
+```
+
### view [design] [view] [param1] [param2] ...
-**Description:** Retriew a particular view in design document for given database.
+**Description:** Retrieve a particular view in design document for given database.
**Example:**
@@ -100,7 +100,7 @@ databaseCommands._allViews = function(input, cli) {
} else {
views = Object.keys(document.body('views'));
- databaseCallbacks['allViews'](views);
+ databaseCallbacks.allViews(views);
}
});
} else {
@@ -144,6 +144,53 @@ databaseCommands._document = function(input, cli) {
/**
+ * Display temporary view for given database.
+ *
+ * @param {Array} input Array of ' ' splitted input arguments
+ * @param {Object} cli general cli object
+ *
+ * @private
+ */
+databaseCommands._tmpView = function(input, cli) {
+ var args = input.slice(1, input.length),
+ map = args.shift(),
+ newArgs = [map],
+ paramsObject,
+ reduce;
+
+ if (args.length && args[args.length - 1].match(/function/g)) {
+ reduce = args.pop();
+ }
+
+ // TODO what happens if there is a parse error????
+ // define case for return undefined
+ paramsObject = cHelper._createParamsObject(args);
+
+ if (paramsObject && Object.keys(paramsObject).length) {
+ newArgs.push(paramsObject);
+
+ } else {
+ if (paramsObject === undefined) {
+ console.log('There was invalid parameter input');
+ console.log('Look for help with:\n');
+ console.log(' $ help view');
+
+ cli.prompt();
+
+ return;
+ }
+ }
+
+ if (reduce) {
+ newArgs.push(reduce);
+ }
+
+ newArgs.push(databaseCallbacks.view);
+
+ cli.db.temporaryView.apply(cli.db, newArgs);
+};
+
+/**
* Display given view for given database.
*
* @param {Array} input Array of ' ' splitted input arguments
@@ -165,7 +212,7 @@ databaseCommands._view = function(input, cli) {
paramsObject = cHelper._createParamsObject(params);
if (paramsObject !== undefined) {
- args.push(paramsObject, databaseCallbacks['view']);
+ args.push(paramsObject, databaseCallbacks.view);
cli.db.view.apply(cli.db, args);
} else {
console.log('There was invalid parameter input');
View
@@ -104,7 +104,7 @@ var messages = module.exports = {
' $ deleteAdmin [name]',
'deleteConnection': 'Delete particular saved connection.\n\n' +
- 'Command:\n' +
+ 'Commands:\n' +
'Delete saved connection by its name' +
' $ deleteConnection [name]' +
'Delete saved connection by its index' +
@@ -182,6 +182,17 @@ var messages = module.exports = {
'Command:\n' +
' $ stats',
+ 'tmpView': 'Retrieve a temporary view for given database,\n\n' +
+ 'Commands:\n' +
+ ' $ tmpView [map]\n' +
+ ' -> tmpView \'function(doc) {emit(doc._id, doc);}\'\n\n' +
+ ' $ tmpView [map] [param1] [param2] ...\n' +
+ ' -> tmpView \'function(doc) {emit(doc._id, doc);}\' limit=1 skip=2\n\n' +
+ ' $ tmpView [map] [reduce]\n' +
+ ' -> tmpView \'function(doc) {emit(doc._id, doc);}\' \'function(keys, values, rereduce){return sum(); }\'\n\n' +
+ ' $tmpView [map] [param1] [paran2] ... [reduce]\n' +
+ ' -> tmpView \'function(doc) {emit(doc._id, doc);}\' limit=1 skip=2 \'function(keys, values, rereduce){return sum(); }\'',
+
'user': 'Switch to a given user level.\n' +
'You can switch to an existing user or' +
'into the level of a new user by setting his/her' +

0 comments on commit 2c41e7f

Please sign in to comment.