UNPKG

9.57 kBMarkdownView Raw
1Queries
2=======
3
4
5MysqlLayer and PostgresLayer
6==========
7
8 ---
9 // Create a record
10 env.i.do("data.Blueprint.create", {
11 path: "test.path",
12 alalala:333,
13 name: "Some name",
14 }, function(err, record){
15 console.log("data.Blueprint.create", record);
16 });
17
18 ---
19
20 // Find all records
21 env.i.do("data.Blueprint.find", function(err, records){
22 console.log("data.Blueprint.find", records);
23 });
24
25 ---
26
27 // Find one record by id
28 env.i.do("data.Blueprint.find", 5, function(err, record){
29 console.log("????", record);
30 });
31
32 ---
33
34 // Find multiple records by array of ids
35 env.i.do("data.Blueprint.find", [5,6,7], function(err, records){
36 console.log("data.Blueprint.find", records);
37 });
38
39 ---
40
41 // Find multiple records by condition
42 env.i.do("data.Blueprint.find", {
43 name: ["NOT IN", '1434118856493', 1434118849186], // 1434118849186 || [ 1434118849186, 1434118849186 ] || [">=", 1434118849186, 1434118849186 ]
44 path: 'test.path'
45 }, function(err, records){
46 console.log("data.Blueprint.find", records);
47 });
48
49 ---
50
51 // Find multiple records by condition and some options
52 env.i.do("data.Blueprint.find", {
53 name: [">", 0], // 1434118849186 || [ 1434118849186, 1434118849186 ] || [">=", 1434118849186, 1434118849186 ]
54 path: 'test.path'
55 }, {
56 limit: [3, 3],
57 order: ["name", "DESC"]
58 }, function(err, records){
59 console.log("data.Blueprint.find", records);
60 });
61
62 ---
63
64 // Update record
65 env.i.do("data.Blueprint.update", {
66 // if primaryKey provided - only one record will be updated
67 name: [">", 0], // varriants: 1434118849186 || [ 1434118849186, 1434118849186 ] || [">=", 1434118849186, 1434118849186 ]
68 path: 'test.path'
69 }, {
70 // where: { ... } - if omitted, all records will be updated, otherwise where clause will be generated
71 limit: [3, 3],
72 order: ["name", "DESC"]
73 }, function(err, result){
74 console.log("data.Blueprint.update", result);
75 });
76
77 ---
78
79 // Delete all record
80 env.i.do("data.Blueprint.delete", function(err, result){
81 console.log("data.Blueprint.delete", result);
82 });
83
84 // Delete one record by id
85 env.i.do("data.Blueprint.delete", 15, function(err, result){
86 console.log("data.Blueprint.delete", result);
87 });
88
89 // Delete with where condition
90 env.i.do("data.Blueprint.delete", field: value, otrherField: ["Between"], function(err, result){
91 console.log("data.Blueprint.delete", result);
92 });
93
94RedisLayer
95==========
96
97 ---
98 // Create record
99 env.i.do("data.Cache.create", {alabala: 535353, value: {
100 something: 5,
101 other: Date.now()
102 }}, function(err, result){
103 if(err) return env.i.do("log.error", "data.Cache.create - test", err);
104 else{
105 console.log("success", result);
106 }
107 });
108
109
110 ---
111
112 // Get all records
113 env.i.do("data.Cache.find", function(err, result){
114 if(err) return env.i.do("log.error", "data.Cache.create - test", err);
115 else{
116 console.log("success", result);
117 }
118 });
119
120 // Get record by id
121 env.i.do("data.Cache.find", 11, {fields: ["value"]}, function(err, result){
122 if(err) return env.i.do("log.error", "data.Cache.create - test", err);
123 else{
124 console.log("success", result);
125 }
126 });
127
128 // Get records by array of ids
129 env.i.do("data.Cache.find", [10,11,12,13], {fields: ["value"]}, function(err, result){
130 if(err) return env.i.do("log.error", "data.Cache.create - test", err);
131 else{
132 console.log("success", result);
133 }
134 });
135
136 // Find with 'fields' option
137 env.i.do("data.Cache.find", [123,234], {fields: ["field1", "field2"]}, function(err, result){
138 if(err) return env.i.do("log.error", "data.Cache.create - test", err);
139 else{
140 console.log("success", result);
141 }
142 });
143
144 ---
145
146
147 // Update single record
148 env.i.do("data.Cache.update", {field: value, primaryKey: 12}, function(err, result){
149 console.log("success: delete", arguments);
150 });
151
152 // Update multiple records
153 env.i.do("data.Cache.update", [
154 {field: value, primaryKey: 12},
155 {field: value, primaryKey: 13},
156 {field: value, primaryKey: 14},
157 {field: value, primaryKey: 15},
158 ], function(err, result){
159 console.log("success: update", arguments);
160 });
161
162 // Delete all records
163 env.i.do("data.Cache.update", null, function(err, result){
164 console.log("success: update", arguments);
165 });
166
167 ---
168
169 // Delete single record
170 env.i.do("data.Cache.delete", 11, function(err, result){
171 console.log("success: delete", arguments);
172 });
173
174 // Delete multiple records
175 env.i.do("data.Cache.delete", [11, 12, 13], function(err, result){
176 console.log("success: delete", arguments);
177 });
178
179 // Delete all records
180 env.i.do("data.Cache.delete", null, function(err, result){
181 console.log("success: delete", arguments);
182 });
183
184 ---
185
186ElasticLayer
187============
188
189
190 Create record in the index
191 env.i.do("data.Posts.create", {
192 // post_id: "---", // will be omited
193 user_id: "user_id",
194 title: "title",
195 created_at: "created_at",
196 updated_at: "updated_at",
197 body: "body"
198 }, function(err, post){
199 console.log("data.Posts.create:::", post);
200 });
201
202 ---
203
204 Get all from this index
205 env.i.do("data.Posts.find", function(err, posts){
206 console.log("data.Posts.find:::", posts);
207 });
208
209 Get by id
210 env.i.do("data.Posts.find", 'RcW9mjKbSkSuUNC6t3nCtg', function(err, posts){
211 console.log("data.Posts.find:::", posts);
212 });
213
214 Get by list of ids
215 env.i.do("data.Posts.find", ['L-vuDpi-Qj297X-LlUHzDA', 'lw8wr96aRb2H6vSTULM8RA'], function(err, posts){
216 console.log("data.Posts.find:::", posts);
217 });
218
219 Get by elastic query search (will be addes as body)
220 https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-search
221 env.i.do("data.Posts.find", {
222 query: {
223 match: {
224 created_at: 'created_at'
225 }
226 }
227 }, function(err, posts){
228 console.log("data.Posts.find:::", posts);
229 });
230
231
232 Get by elastic multimle query search (will be addes as body)
233 https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-msearch
234 If there is {type: "type"}, will be extended with index
235 otherwise will prepend the query with index: indexName
236 env.i.do("data.Posts.find", [
237 {query: { match: { created_at: 'created_at' } } },
238 {query: { match: { updated_at: 'updated_at' } } },
239 ], function(err, posts){
240 console.log("data.Posts.find:::", posts);
241 });
242
243 ---
244
245 Update single document (if primary key is provided)
246 https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-update
247 env.i.do("data.Posts.update", {
248 user_id: 'user_id_updated_'+Date.now(),
249 title: 'updated title',
250 created_at: 'created_at',
251 updated_at: 'updated_at',
252 body: 'body',
253 post_id: 'RcW9mjKbSkSuUNC6t3nCtg'
254 }, function(err, posts){
255 if(err) return console.log("data.Posts.update:::error", err);
256 console.log("data.Posts.mass update:::", posts);
257 });
258
259
260 Update multiple documents (if no 'where' in options - will update all documents in index)
261 'where' shuld be argument like in find - single id, array of id-s, search pattern
262 env.i.do("data.Posts.update", {
263 updated_at: 'updated_at',
264 }, function(err, posts){
265 if(err) return console.log("data.Posts.update:::error", err);
266 console.log("data.Posts.update:::mass update", posts);
267 });
268
269
270 Update multiple documents (array of docuyments, containing id attribute every)
271 'where' in options shuld be argument like in find - single id, array of id-s, search pattern ...
272 env.i.do("data.Posts.update", {
273 updated_at: 'updated_at',
274 }, {where: 'find query here' }, function(err, posts){
275 if(err) return console.log("data.Posts.update:::error", err);
276 console.log("data.Posts.update:::mass update", posts);
277 });
278
279 Update multiple models as array
280 env.i.do("data.Posts.update", [ { title: 'Mass updated title', post_id: 'qP5_KoDdSlONZrTwT4qghw' },
281 {aaa: 444, title: 'Mass updated test invalid props', post_id: 'lw8wr96aRb2H6vSTULM8RA' },
282 {aaa: 444, title: 'Mass updated test invalid props', post_id: 'HoE2yEv-RS-ErfFT_dK2nQ' },
283 {aaa: 444, title: 'Mass updated test invalid props', post_id: '7U_ElH90R1-oH9lXhAsXQA' },
284 ], function(err, updated){
285 if(err) return console.log("error: ", err);
286 console.log("data.Posts.update:::mass update", updated );
287 });
288
289 ---
290
291 Delete single record by id
292 env.i.do("data.Posts.delete", '7U_ElH90R1-oH9lXhAsXQA', function(err, result){
293 console.log("delete: ", arguments);
294 });
295 or by object, containing with primaryKey
296 env.i.do("data.Posts.delete", {post_id: '7U_ElH90R1-oH9lXhAsXQA'}, function(err, result){
297 console.log("delete: ", arguments);
298 });
299
300 if object does not contain id - delete by query
301 https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-deletebyquery
302 env.i.do("data.Posts.delete", {query: {...}}, function(err, result){
303 console.log("delete: ", arguments);
304 });