You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/21 22:20:50 UTC

[7/8] git commit: add "delete by query" functionality

add "delete by query" functionality


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/be803f75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/be803f75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/be803f75

Branch: refs/heads/node-sdk-enhancements
Commit: be803f759594133f90de6892ce7fb354307853a0
Parents: 0fc9cd6
Author: Scott Ganyo <sc...@ganyo.com>
Authored: Fri Mar 21 14:11:11 2014 -0700
Committer: Scott Ganyo <sc...@ganyo.com>
Committed: Fri Mar 21 14:11:11 2014 -0700

----------------------------------------------------------------------
 sdks/nodejs/lib/usergrid.js | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/be803f75/sdks/nodejs/lib/usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/nodejs/lib/usergrid.js b/sdks/nodejs/lib/usergrid.js
index 55908ef..837a6d0 100755
--- a/sdks/nodejs/lib/usergrid.js
+++ b/sdks/nodejs/lib/usergrid.js
@@ -1472,6 +1472,36 @@ var AUTH_NONE = 'NONE';
     });
   }
 
+/*
+ *  calls delete on the database w/ the passed query
+ *
+ *  @method delete
+ *  @param {opts} options containing query (include options.qs)
+ *  @param {function} callback
+ *  @return {callback} callback(err, data)
+ *
+ */
+Usergrid.client.prototype.delete = function(opts, callback) {
+  if (_.isFunction(opts)) { callback = opts; opts = undefined; }
+
+  if (!opts.qs.q) { opts.qs.q = '*'; }
+
+  var options = {
+    method: 'DELETE',
+    endpoint: opts.type,
+    qs: opts.qs
+  };
+  var self = this;
+  this.request(options, function (err, data) {
+    if (err && self.logging) {
+      console.log('entities could not be deleted');
+    }
+    if (typeof(callback) === 'function') {
+      callback(err, data);
+    }
+  });
+};
+
   /*
   *  The Collection class models Usergrid Collections.  It essentially
   *  acts as a container for holding Entity objects, while providing