Skip to content

Commit d87dab8

Browse files
feat: compare query operators implementation
1 parent 2e41ccb commit d87dab8

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/lib/query.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,76 @@ export class Query extends BaseQuery {
371371
this._queryParams['typeahead'] = key
372372
return this
373373
}
374+
375+
/**
376+
* @method lessThan
377+
* @memberof Query
378+
* @description Returns the raw (JSON) query based on the filters applied on Query object.
379+
* @example
380+
* import contentstack from '@contentstack/delivery-sdk'
381+
*
382+
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
383+
* const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
384+
* const entryQuery = await stack.contentType('contenttype_uid').query().lessThan('fieldUid', 'value').find();
385+
*
386+
* @returns {Query}
387+
*/
388+
lessThan(key: string, value: (string | number)): Query {
389+
this._parameters[key] = { '$lt': value };
390+
return this;
391+
}
392+
393+
/**
394+
* @method lessThanOrEqualTo
395+
* @memberof Query
396+
* @description Returns the raw (JSON) query based on the filters applied on Query object.
397+
* @example
398+
* import contentstack from '@contentstack/delivery-sdk'
399+
*
400+
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
401+
* const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
402+
* const entryQuery = await stack.contentType('contenttype_uid').query().lessThanOrEqualTo('fieldUid', 'value').find();
403+
*
404+
* @returns {Query}
405+
*/
406+
lessThanOrEqualTo(key: string, value: (string | number)): Query {
407+
this._parameters[key] = { '$lte': value };
408+
return this;
409+
}
410+
411+
/**
412+
* @method greaterThan
413+
* @memberof Query
414+
* @description Returns the raw (JSON) query based on the filters applied on Query object.
415+
* @example
416+
* import contentstack from '@contentstack/delivery-sdk'
417+
*
418+
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
419+
* const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
420+
* const entryQuery = await stack.contentType('contenttype_uid').query().greaterThan('fieldUid', 'value').find();
421+
*
422+
* @returns {Query}
423+
*/
424+
greaterThan(key: string, value: (string | number)): Query {
425+
this._parameters[key] = { '$gt': value };
426+
return this;
427+
}
428+
429+
/**
430+
* @method greaterThanOrEqualTo
431+
* @memberof Query
432+
* @description Returns the raw (JSON) query based on the filters applied on Query object.
433+
* @example
434+
* import contentstack from '@contentstack/delivery-sdk'
435+
*
436+
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
437+
* const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
438+
* const entryQuery = await stack.contentType('contenttype_uid').query().greaterThanOrEqualTo('fieldUid', 'value').find();
439+
*
440+
* @returns {Query}
441+
*/
442+
greaterThanOrEqualTo(key: string, value: (string | number)): Query {
443+
this._parameters[key] = { '$gte': value };
444+
return this;
445+
}
374446
}

0 commit comments

Comments
 (0)