-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathQueryable.js
139 lines (123 loc) · 3.48 KB
/
Queryable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import Builder from './Query/Builder';
import Create from './Services/Create';
import DeleteAll from './Services/DeleteAll';
import FindAll from './Services/FindAll';
import FindById from './Services/FindById';
import FindWithinDistance from './Services/FindWithinDistance';
import First from './Services/First';
import MergeOn from './Services/MergeOn';
export default class Queryable {
/**
* @constructor
*
* @param Neode neode
*/
constructor(neode) {
this._neode = neode;
}
/**
* Return a new Query Builder
*
* @return {Builder}
*/
query() {
return new Builder(this._neode);
}
/**
* Create a new instance of this Model
*
* @param {object} properties
* @return {Promise}
*/
create(properties) {
return Create(this._neode, this, properties);
}
/**
* Merge a node based on the defined indexes
*
* @param {Object} properties
* @return {Promise}
*/
merge(properties) {
const merge_on = this.mergeFields();
return MergeOn(this._neode, this, merge_on, properties);
}
/**
* Merge a node based on the supplied properties
*
* @param {Object} match Specific properties to merge on
* @param {Object} set Properties to set
* @return {Promise}
*/
mergeOn(match, set) {
const merge_on = Object.keys(match);
const properties = Object.assign({}, match, set);
return MergeOn(this._neode, this, merge_on, properties);
}
/**
* Delete all nodes for this model
*
* @return {Promise}
*/
deleteAll() {
return DeleteAll(this._neode, this);
}
/**
* Get a collection of nodes for this label
*
* @param {Object} properties
* @param {String|Array|Object} order
* @param {Int} limit
* @param {Int} skip
* @return {Promise}
*/
all(properties, order, limit, skip) {
return FindAll(this._neode, this, properties, order, limit, skip);
}
/**
* Find a Node by its Primary Key
*
* @param {mixed} id
* @return {Promise}
*/
find(id) {
const primary_key = this.primaryKey();
return this.first(primary_key, id);
}
/**
* Find a Node by it's internal node ID
*
* @param {String} model
* @param {int} id
* @return {Promise}
*/
findById(id) {
return FindById(this._neode, this, id);
}
/**
* Find a Node by properties
*
* @param {String} label
* @param {mixed} key Either a string for the property name or an object of values
* @param {mixed} value Value
* @return {Promise}
*/
first(key, value) {
return First(this._neode, this, key, value);
}
/**
* Get a collection of nodes within a certain distance belonging to this label
*
* @param {Object} properties
* @param {String} location_property
* @param {Object} point
* @param {Int} distance
* @param {String|Array|Object} order
* @param {Int} limit
* @param {Int} skip
* @return {Promise}
*/
withinDistance(location_property, point, distance, properties, order, limit, skip) {
return FindWithinDistance(this._neode, this, location_property, point, distance, properties, order, limit, skip);
}
}