@@ -261,6 +261,75 @@ export default class ParseQuery {
261
261
return params ;
262
262
}
263
263
264
+ /**
265
+ * Return a query with conditions from json, can be useful to send query from server side to client
266
+ * Not static, all query conditions was set before calling this method will be deleted.
267
+ * For example on the server side we have
268
+ * var query = new Parse.Query("className");
269
+ * query.equalTo(key: value);
270
+ * query.limit(100);
271
+ * ... (others queries)
272
+ * Create JSON representation of Query Object
273
+ * var jsonFromServer = query.fromJSON();
274
+ *
275
+ * On client side getting query:
276
+ * var query = new Parse.Query("className");
277
+ * query.fromJSON(jsonFromServer);
278
+ *
279
+ * and continue to query...
280
+ * query.skip(100).find().then(...);
281
+ * @method withJSON
282
+ * @param {QueryJSON } json from Parse.Query.toJSON() method
283
+ * @return {Parse.Query } Returns the query, so you can chain this call.
284
+ */
285
+ withJSON ( json : QueryJSON ) : ParseQuery {
286
+
287
+ if ( json . where ) {
288
+ this . _where = json . where ;
289
+ }
290
+
291
+ if ( json . include ) {
292
+ this . _include = json . include . split ( "," ) ;
293
+ }
294
+
295
+ if ( json . keys ) {
296
+ this . _select = json . keys . split ( "," ) ;
297
+ }
298
+
299
+ if ( json . limit ) {
300
+ this . _limit = json . limit ;
301
+ }
302
+
303
+ if ( json . skip ) {
304
+ this . _skip = json . skip ;
305
+ }
306
+
307
+ if ( json . order ) {
308
+ this . _order = json . order . split ( "," ) ;
309
+ }
310
+
311
+ for ( let key in json ) if ( json . hasOwnProperty ( key ) ) {
312
+ if ( [ "where" , "include" , "keys" , "limit" , "skip" , "order" ] . indexOf ( key ) === - 1 ) {
313
+ this . _extraOptions [ key ] = json [ key ] ;
314
+ }
315
+ }
316
+
317
+ return this ;
318
+
319
+ }
320
+
321
+ /**
322
+ * Static method to restore Parse.Query by json representation
323
+ * Internally calling Parse.Query.withJSON
324
+ * @param {String } className
325
+ * @param {QueryJSON } json from Parse.Query.toJSON() method
326
+ * @returns {Parse.Query } new created query
327
+ */
328
+ static fromJSON ( className : string , json : QueryJSON ) : ParseQuery {
329
+ const query = new ParseQuery ( className ) ;
330
+ return query . withJSON ( json ) ;
331
+ }
332
+
264
333
/**
265
334
* Constructs a Parse.Object whose id is already known by fetching data from
266
335
* the server. Either options.success or options.error is called when the
0 commit comments