{"id":18908794,"url":"https://github.com/mrphu3074/realm-query","last_synced_at":"2025-04-15T05:32:07.590Z","repository":{"id":57348883,"uuid":"89125208","full_name":"mrphu3074/realm-query","owner":"mrphu3074","description":"A query builder for realm.js","archived":false,"fork":false,"pushed_at":"2018-01-24T03:13:36.000Z","size":45,"stargazers_count":27,"open_issues_count":3,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-05T06:57:33.419Z","etag":null,"topics":["node","react-native","realm","realm-js"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrphu3074.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-23T07:36:22.000Z","updated_at":"2023-05-11T13:48:21.000Z","dependencies_parsed_at":"2022-08-31T17:50:57.672Z","dependency_job_id":null,"html_url":"https://github.com/mrphu3074/realm-query","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrphu3074%2Frealm-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrphu3074%2Frealm-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrphu3074%2Frealm-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrphu3074%2Frealm-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrphu3074","download_url":"https://codeload.github.com/mrphu3074/realm-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223660505,"owners_count":17181515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node","react-native","realm","realm-js"],"created_at":"2024-11-08T09:28:35.375Z","updated_at":"2024-11-08T09:28:36.091Z","avatar_url":"https://github.com/mrphu3074.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/mrphu3074/realm-query/tree/master.svg?style=svg)](https://circleci.com/gh/mrphu3074/realm-query/tree/master)\n\n[![Test Coverage](https://codeclimate.com/github/codeclimate/codeclimate/badges/coverage.svg)](https://codeclimate.com/github/codeclimate/codeclimate/coverage)\n\n[![Code Climate](https://codeclimate.com/github/codeclimate/codeclimate/badges/gpa.svg)](https://codeclimate.com/github/codeclimate/codeclimate)\n\n---- \n\n# Realm Query\n\nA query builder for realm.js inspired of Realm Java's query engine.\n\nhttps://realm.io/docs/java/latest/#queries\n\n## Installation\n\n```console\n$ npm install --save realm-query\n# or\n$ yarn add realm-query\n```\n\n## Usage\n\n```javascript\nconst RealmQuery = require('realm-query');\nconst realm = new Realm({...});\n\n// Way 1\nlet query = RealmQuery\n  .create()\n  .contains('name', 'phu', true)\n  .in('id', [1001, 1002]);\n\n// get objects\n// query.toString() = name CONTAINS[c] \"phu\" AND (id == 1001 OR id == 1002)\nlet results = realm.objects('Person').filtered(query.toString());\n\n// Way 2. use lib to get objects\nlet results = RealmQuery\n                .where(realm.objects('Person'))\n                .contains('name', 'phu', true)\n                .in('id', [1001, 1002])\n                .findAll()\n\n// Complex query\nlet results = RealmQuery\n                .where(realm.objects('Person'))\n                .contains('name', 'phu', true)\n                .beginGroup()\n                  .in('id', [1001, 1002])\n                  .or()\n                  .between('age', 20, 45)\n                .endGroup()\n                .sort('id', 'DESC')\n                .findAll()\n// It will query like this\n// name CONTAINS[c] \"phu\" AND ((id == 1001 OR id == 1002) OR (age \u003e= 20 AND age \u003c= 45))\n// and sort by id desc\n```\n\n## API\n\n- #### average(fieldName: string): number\n  _Returns the average of a given field_\n\n- #### beginGroup(): RealmQuery\n  _Begin grouping of conditions (\"left parenthesis\")_\n\n- #### beginsWith(fieldName: string, value: string, casing?: boolean): RealmQuery\n  _Condition that the value of field begins with the specified string_\n\n- #### between(fieldName: string, from: number|date, to: number|date): RealmQuery\n  _Between condition_\n\n- #### contains(fieldName: string, value: string, casing?: boolean): RealmQuery\n  _Condition that value of field contains the specified substring_\n\n- #### count(): number\n  _Counts the number of objects that fulfill the query conditions_\n\n- #### distinct(fieldName: string): Array\u003cResultItem\u003e\n  _Returns a distinct set of objects of a specific class._\n\n- #### endGroup(): RealmQuery\n  _End grouping of conditions (\"right parenthesis\") which was opened by a call to beginGroup()_\n\n- #### endsWith(fieldName: string, value: string, casing?: boolean): RealmQuery\n  _Condition that the value of field ends with the specified string_\n\n- #### equalTo(fieldName: string, value: string|number|boolean|date): RealmQuery\n  _Equal-to comparison_\n\n- #### findAll(): ReamResults\n  _Finds all objects that fulfill the query conditions_\n\n- #### findFirst(): Object\n  \n  _Finds the first object that fulfills the query conditions_\n\n- #### greaterThan(fieldName: string, value: number|date): RealmQuery\n  _Greater-than comparison_\n\n- #### greaterThanOrEqualTo(fieldName: string, value: number|date): RealmQuery\n  _greater-than-or-equal-to comparison_\n\n- #### in(fieldName: string, values: string|number[]): RealmQuery\n  _In comparison_\n\n- #### lessThan(fieldName: string, value: number|date): RealmQuery\n  _Less-than comparison_\n\n- #### lessThanOrEqualTo(fieldName: string, value: number|date): RealmQuery\n  _Less-than-or-equal-to comparison_\n\n- #### max(fieldName: string): Object\n  _Finds the maximum value of a field_\n\n- #### min(fieldName: string): Object\n  _Finds the miniimum value of a field_\n\n- #### not(): RealmQuery\n  _Negate condition_\n  \n- #### notEqualTo(fieldName: string, value: string|number|boolean|date): RealmQuery\n  _Not-equal-to comparison_\n  \n- #### and(): RealmQuery\n  _AND logic operator. Use in group_\n  \n- #### or(): RealmQuery\n  _OR logic operator. Use in group_\n  ```javascript\n  let results = RealmQuery\n        .where(realm.objects('Person'))\n        .contains('name', 'phu', true)\n        .beginGroup()\n          .in('id', [1001, 1002])\n          .or()\n          .between('age', 20, 45)\n        .endGroup()\n        .findAll()\n  ```\n\n- #### sum(): number\n  _Calculates the sum of a given field_\n\n- #### sort(fieldName: string, order?: 'ASC' | 'DESC'): RealmQuery\n  _Set sorted into realm.objects_\n\n- #### join(query: RealmQuery): RealmQuery\n  _Join queries_\n  ```javascript\n  let query1 = RealmQuery\n    .where(realm.objects('Person'))\n    .in('id', [1001, 1002])\n  let query2 = RealmQuery\n    .where(realm.objects('Person'))\n    .greaterThan('age', 25);\n  query1.join(query2);\n  \n  query1.toString = (id == 1001 OR id == 1002) AND age \u003e 25\n  ```\n\n- #### where(objects?: RealmResults): RealmQuery\n  _Create new query_\n\n- #### create(objects?: RealmResults): RealmQuery\n  _Create new query. Alias of where_\n\n---\n\n## [Changelog](CHANGELOG.md)\n\n## [License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrphu3074%2Frealm-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrphu3074%2Frealm-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrphu3074%2Frealm-query/lists"}