Permalink
Browse files

added indexUniquely for nodes and added all new index functions to re…

…lationships
  • Loading branch information...
1 parent 2a9b249 commit 9d7581e866b4d4a7ac27798a859af7c925b82900 @flipside committed Oct 11, 2012
Showing with 360 additions and 30 deletions.
  1. +71 −0 lib/GraphDatabase._coffee
  2. +55 −6 lib/GraphDatabase.js
  3. +35 −1 lib/Node._coffee
  4. +44 −20 lib/Node.js
  5. +89 −2 lib/Relationship._coffee
  6. +66 −1 lib/Relationship.js
@@ -480,6 +480,77 @@ module.exports = class GraphDatabase
catch error
throw adjustError error
+ #
+ # Get list of relationship indexes.
+ #
+ # @param callback {Function}
+ #
+ getRelationshipIndexes: (_) ->
+ try
+ services = @getServices _
+
+ url = "#{services.relationship_index}/"
+
+ response = @_request.get url, _
+
+ if response.statusCode isnt status.OK
+ # Database error
+ throw response
+
+ # Success
+ return response.body
+
+ catch error
+ throw adjustError error
+
+ #
+ # Create relationship index.
+ #
+ # @param index {String}
+ # @param callback {Function}
+ #
+ createRelationshipIndex: (index, _) ->
+ try
+ services = @getServices _
+
+ response = @_request.post
+ url: "#{services.relationship_index}/"
+ json:
+ name: index
+ , _
+
+ if response.statusCode isnt status.CREATED
+ # Database error
+ throw response
+
+ # Success
+ return response.body
+
+ catch error
+ throw adjustError error
+
+ #
+ # Delete a relationship index.
+ #
+ # @param index {String}
+ # @param callback {Function}
+ #
+ deleteRelationshipIndex: (index, _) ->
+ try
+ services = @getServices _
+
+ url = "#{services.relationship_index}/#{index}"
+ response = @_request.del url, _
+
+ if response.statusCode isnt status.NO_CONTENT
+ # Database error
+ throw response
+
+ # Success
+ return response
+
+ catch error
+ throw adjustError error
### Misc/Other: ###
View
@@ -279,14 +279,63 @@
+ GraphDatabase.prototype.getRelationshipIndexes = function GraphDatabase_prototype_getRelationshipIndexes__17(_) { var response, services, url, __this = this; var __frame = { name: "GraphDatabase_prototype_getRelationshipIndexes__17", line: 282 }; return __func(_, this, arguments, GraphDatabase_prototype_getRelationshipIndexes__17, 0, __frame, function __$GraphDatabase_prototype_getRelationshipIndexes__17() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_getRelationshipIndexes__17() {
+
+
+ return __this.getServices(__cb(_, __frame, 3, 19, function ___(__0, __1) { services = __1;
+ url = (("" + services.relationship_index) + "/");
+ return __this._request.get(url, __cb(_, __frame, 5, 19, function ___(__0, __2) { response = __2;
+ if ((response.statusCode !== status.OK)) {
+ return _(response); } ;
+
+ return _(null, response.body); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_getRelationshipIndexes__17() { if (error) {
+
+ return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
+
+
+
+ GraphDatabase.prototype.createRelationshipIndex = function GraphDatabase_prototype_createRelationshipIndex__18(index, _) { var response, services, __this = this; var __frame = { name: "GraphDatabase_prototype_createRelationshipIndex__18", line: 297 }; return __func(_, this, arguments, GraphDatabase_prototype_createRelationshipIndex__18, 1, __frame, function __$GraphDatabase_prototype_createRelationshipIndex__18() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_createRelationshipIndex__18() {
+
+
+ return __this.getServices(__cb(_, __frame, 3, 19, function ___(__0, __1) { services = __1;
+ return __this._request.post({
+ url: (("" + services.relationship_index) + "/"),
+ json: {
+ name: index } }, __cb(_, __frame, 4, 19, function ___(__0, __2) { response = __2;
+
+
+ if ((response.statusCode !== status.CREATED)) {
+ return _(response); } ;
+
+ return _(null, response.body); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_createRelationshipIndex__18() { if (error) {
+
+ return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
+
+
+
+ GraphDatabase.prototype.deleteRelationshipIndex = function GraphDatabase_prototype_deleteRelationshipIndex__19(index, _) { var response, services, url, __this = this; var __frame = { name: "GraphDatabase_prototype_deleteRelationshipIndex__19", line: 316 }; return __func(_, this, arguments, GraphDatabase_prototype_deleteRelationshipIndex__19, 1, __frame, function __$GraphDatabase_prototype_deleteRelationshipIndex__19() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_deleteRelationshipIndex__19() {
+
+
+ return __this.getServices(__cb(_, __frame, 3, 19, function ___(__0, __1) { services = __1;
+ url = ((("" + services.relationship_index) + "/") + index);
+ return __this._request.del(url, __cb(_, __frame, 5, 19, function ___(__0, __2) { response = __2;
+ if ((response.statusCode !== status.NO_CONTENT)) {
+ return _(response); } ;
+
+ return _(null, response); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_deleteRelationshipIndex__19() { if (error) {
+
+ return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
+
+
+
- GraphDatabase.prototype.query = function GraphDatabase_prototype_query__17(query, params, _) { var body, columns, endpoint, i, map, response, results, row, services, value, _ref, _ref1, __this = this; var __frame = { name: "GraphDatabase_prototype_query__17", line: 286 }; return __func(_, this, arguments, GraphDatabase_prototype_query__17, 2, __frame, function __$GraphDatabase_prototype_query__17() {
+ GraphDatabase.prototype.query = function GraphDatabase_prototype_query__20(query, params, _) { var body, columns, endpoint, i, map, response, results, row, services, value, _ref, _ref1, __this = this; var __frame = { name: "GraphDatabase_prototype_query__20", line: 335 }; return __func(_, this, arguments, GraphDatabase_prototype_query__20, 2, __frame, function __$GraphDatabase_prototype_query__20() {
if ((params == null)) {
- params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_query__17() {
+ params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_query__20() {
return __this.getServices(__cb(_, __frame, 6, 19, function ___(__0, __2) { services = __2;
@@ -324,7 +373,7 @@
return (function __1(_) { var _i, _j, _len, _len1, _ref2, _results; _ref2 = body.data; _results = []; for (_i = 0, _len = _ref2.length; (_i < _len); _i++) { row = _ref2[_i]; map = { }; for (i = _j = 0, _len1 = row.length; (_j < _len1); i = ++_j) { value = row[i]; map[columns[i]] = util.transform(value, __this); }; _results.push(map); }; return _(null, _results); })(__cb(_, __frame, 40, 18, function ___(__0, __4) { results = __4;
- return _(null, results); }, true)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_query__17() { if (error) {
+ return _(null, results); }, true)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_query__20() { if (error) {
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
@@ -345,10 +394,10 @@
})(GraphDatabase.prototype.query);
- GraphDatabase.prototype.execute = function GraphDatabase_prototype_execute__18(script, params, _) { var endpoint, response, services, _ref, _ref1, __this = this; var __frame = { name: "GraphDatabase_prototype_execute__18", line: 348 }; return __func(_, this, arguments, GraphDatabase_prototype_execute__18, 2, __frame, function __$GraphDatabase_prototype_execute__18() {
+ GraphDatabase.prototype.execute = function GraphDatabase_prototype_execute__21(script, params, _) { var endpoint, response, services, _ref, _ref1, __this = this; var __frame = { name: "GraphDatabase_prototype_execute__21", line: 397 }; return __func(_, this, arguments, GraphDatabase_prototype_execute__21, 2, __frame, function __$GraphDatabase_prototype_execute__21() {
if ((params == null)) {
- params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_execute__18() {
+ params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_execute__21() {
return __this.getServices(__cb(_, __frame, 6, 19, function ___(__0, __1) { services = __1;
@@ -369,7 +418,7 @@
if ((response.statusCode !== status.OK)) {
return _(response); } ;
- return _(null, util.transform(response.body, __this)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_execute__18() { if (error) {
+ return _(null, util.transform(response.body, __this)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_execute__21() { if (error) {
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
View
@@ -158,6 +158,40 @@ module.exports = class Node extends PropertyContainer
throw adjustError error
#
+ # Uniquely add this node to the given index under the given key-value pair.
+ #
+ # @param index {String} The name of the index, e.g. `'users'`.
+ # @param key {String} The key to index under, e.g. `'username'`.
+ # @param value {String} The value to index under, e.g. `'aseemk'`.
+ # @param callback {Function}
+ #
+ indexUniquely: (index, key, value, _) ->
+ try
+ # TODO
+ if not @exists
+ throw new Error 'Node must exist before indexing properties'
+
+ services = @db.getServices _
+
+ response = @_request.post
+ url: "#{services.node_index}/#{index}?unique"
+ json:
+ key: key
+ value: value
+ uri: @self
+ , _
+
+ if response.statusCode isnt status.CREATED and response.statusCode isnt status.OK
+ # database error
+ throw response
+
+ # success
+ return response.body
+
+ catch error
+ throw adjustError error
+
+ #
# Delete this node from the given index under the key (optional) and value (optional).
#
# @param index {String} The name of the index, e.g. `'users'`.
@@ -209,7 +243,7 @@ module.exports = class Node extends PropertyContainer
value = null
actual.call @, index, key, value, callback
-
+
#
# Create and "return" (via callback) a relationship of the given type and
# with the given properties from this node to another node.
Oops, something went wrong.

0 comments on commit 9d7581e

Please sign in to comment.