Skip to content

Commit 2a733a5

Browse files
flipsideaseemk
authored andcommitted
added indexUniquely for nodes and added all new index functions to relationships
1 parent 2dc9589 commit 2a733a5

4 files changed

Lines changed: 200 additions & 28 deletions

File tree

lib/GraphDatabase.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,63 @@
279279

280280

281281

282+
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() {
283+
284+
285+
return __this.getServices(__cb(_, __frame, 3, 19, function ___(__0, __1) { services = __1;
286+
url = (("" + services.relationship_index) + "/");
287+
return __this._request.get(url, __cb(_, __frame, 5, 19, function ___(__0, __2) { response = __2;
288+
if ((response.statusCode !== status.OK)) {
289+
return _(response); } ;
290+
291+
return _(null, response.body); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_getRelationshipIndexes__17() { if (error) {
292+
293+
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
294+
295+
296+
297+
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() {
298+
299+
300+
return __this.getServices(__cb(_, __frame, 3, 19, function ___(__0, __1) { services = __1;
301+
return __this._request.post({
302+
url: (("" + services.relationship_index) + "/"),
303+
json: {
304+
name: index } }, __cb(_, __frame, 4, 19, function ___(__0, __2) { response = __2;
305+
306+
307+
if ((response.statusCode !== status.CREATED)) {
308+
return _(response); } ;
309+
310+
return _(null, response.body); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_createRelationshipIndex__18() { if (error) {
311+
312+
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
313+
314+
315+
316+
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() {
317+
318+
319+
return __this.getServices(__cb(_, __frame, 3, 19, function ___(__0, __1) { services = __1;
320+
url = ((("" + services.relationship_index) + "/") + index);
321+
return __this._request.del(url, __cb(_, __frame, 5, 19, function ___(__0, __2) { response = __2;
322+
if ((response.statusCode !== status.NO_CONTENT)) {
323+
return _(response); } ;
324+
325+
return _(null, response); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_deleteRelationshipIndex__19() { if (error) {
326+
327+
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
328+
329+
330+
282331

283332

284333

285334

286-
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() {
335+
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() {
287336

288337
if ((params == null)) {
289-
params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_query__17() {
338+
params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_query__20() {
290339

291340

292341
return __this.getServices(__cb(_, __frame, 6, 19, function ___(__0, __2) { services = __2;
@@ -324,7 +373,7 @@
324373

325374

326375
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;
327-
return _(null, results); }, true)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_query__17() { if (error) {
376+
return _(null, results); }, true)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_query__20() { if (error) {
328377

329378
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
330379

@@ -345,10 +394,10 @@
345394

346395
})(GraphDatabase.prototype.query);
347396

348-
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() {
397+
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() {
349398

350399
if ((params == null)) {
351-
params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_execute__18() {
400+
params = { }; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GraphDatabase_prototype_execute__21() {
352401

353402

354403
return __this.getServices(__cb(_, __frame, 6, 19, function ___(__0, __1) { services = __1;
@@ -369,7 +418,7 @@
369418
if ((response.statusCode !== status.OK)) {
370419
return _(response); } ;
371420

372-
return _(null, util.transform(response.body, __this)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_execute__18() { if (error) {
421+
return _(null, util.transform(response.body, __this)); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$GraphDatabase_prototype_execute__21() { if (error) {
373422

374423
return _(adjustError(error)); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); }); };
375424

lib/Node._coffee

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,40 @@ module.exports = class Node extends PropertyContainer
161161
catch error
162162
throw adjustError error
163163

164+
#
165+
# Uniquely add this node to the given index under the given key-value pair.
166+
#
167+
# @param index {String} The name of the index, e.g. `'users'`.
168+
# @param key {String} The key to index under, e.g. `'username'`.
169+
# @param value {String} The value to index under, e.g. `'aseemk'`.
170+
# @param callback {Function}
171+
#
172+
indexUniquely: (index, key, value, _) ->
173+
try
174+
# TODO
175+
if not @exists
176+
throw new Error 'Node must exist before indexing properties'
177+
178+
services = @db.getServices _
179+
180+
response = @_request.post
181+
url: "#{services.node_index}/#{index}?unique"
182+
json:
183+
key: key
184+
value: value
185+
uri: @self
186+
, _
187+
188+
if response.statusCode isnt status.CREATED and response.statusCode isnt status.OK
189+
# database error
190+
throw response
191+
192+
# success
193+
return response.body
194+
195+
catch error
196+
throw adjustError error
197+
164198
#
165199
# Delete this node from the given index under the key (optional) and value (optional).
166200
#
@@ -213,7 +247,7 @@ module.exports = class Node extends PropertyContainer
213247
value = null
214248

215249
actual.call @, index, key, value, callback
216-
250+
217251
#
218252
# Uniquely add this node to the given index under the given key-value pair.
219253
#

0 commit comments

Comments
 (0)