Skip to content

Commit 9cd2167

Browse files
authored
DOCSP-36298 : Refactor RQL for JSv12 (#3266)
## Pull Request Info - SDK Docs Consolidation Jira ticket: https://jira.mongodb.org/browse/DOCSP-3629 - Ports legacy RQL models and tests to v12 test suite - Generates updated snippets from v12 `.ts` test file Jira ticket: https://jira.mongodb.org/browse/DOCSP-36618 - Updates Realm Query Language page: - Add language selector - Reference new v12 snippets - Reorganize sections Jira ticket: https://jira.mongodb.org/browse/DOCSP-36265 - Update to indicate support for comparison operators on strings (expanded lexicographical querying) - Add example *Staged Page* - [Realm Query Language](https://preview-mongodbcbullinger.gatsbyjs.io/realm/docsp-36298-rql/sdk/crud/query-engines/realm-query-language/) *Page Source* - [Realm Query Language](https://www.mongodb.com/docs/atlas/device-sdks/realm-query-language) ### PR Author Checklist Before requesting a review for your PR, please check these items: - [x] Open the PR against the `feature-consolidated-sdk-docs` branch instead of `master` - [x] Tag the consolidated page for: - genre - meta.keywords - meta.description #### Naming - [x] Update Realm naming and the language around persistence layer/local/device per [this document](https://docs.google.com/document/d/126OczVxBWAwZ4P5ZsSM29WI3REvONEr1ald-mAwPtyQ/edit?usp=sharing) - [x] Include `.rst` files comply with [the naming guidelines](https://docs.google.com/document/d/1h8cr66zoEVeXytVfvDxlCSsUS5IZwvUQvfSCEXNMpek/edit#heading=h.ulh8b5f2hu9) #### Links and Refs - [x] Create new consolidated SDK ref targets starting with "_sdks-" for relevant sections - [x] Remove or update any SDK-specific refs to use the new consolidated SDK ref targets - N/A ~[ ] [Update any Kotlin API links](https://jira.mongodb.org/browse/DOCSP-32519) to use the new Kotlin SDK roles~ #### Content - [x] Shared code boxes have snippets or placeholders for all 9 languages > NOTE: Omitted Swift and Objective-C from page - N/A ~[ ] API description sections have API details or a generic placeholder for all 9 languages~ - [x] Check related pages for relevant content to include - [x] Create a ticket for missing examples in each relevant SDK: Consolidation Gaps epic ### Reviewer Checklist As a reviewer, please check these items: - [ ] Shared code example boxes contain language-specific snippets or placeholders for every language - [ ] API reference details contain working API reference links or generic content - [ ] Realm naming/language has been updated - [ ] All relevant content from individual SDK pages is present on the consolidated page
1 parent ebc8e9d commit 9cd2167

File tree

47 files changed

+3242
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3242
-757
lines changed

examples/node/legacy/Examples/realm-query-language.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Realm, { BSON } from "realm";
22
import { ItemModel, ProjectModel } from "./schemas/rql-data-models";
33

4-
// Tests for new RQL operators or updates should be placed in the new
5-
// file compatible with JSv12 and later, located at
6-
// examples/node/v12/__tests__/realm-query-language.test.js
4+
/*
5+
DON'T UPDATE THIS FILE. DEPRECATED IN FAVOR OF V12 TESTS.
6+
Tests for new RQL operators or updates should be placed in the new
7+
files compatible with JSv12 and later, located at:
8+
examples/node/v12/__tests__/realm-query-language.test.js/ts
9+
*/
710

811
describe("Realm Query Language Reference", () => {
912
let realm;
@@ -148,7 +151,7 @@ describe("Realm Query Language Reference", () => {
148151
const progressMinutesRange = items.filtered(
149152
// :remove-end:
150153

151-
// Find to-do items within a certain time range by finding items
154+
// Find to-do items within a certain time range by finding items
152155
// where the progressMinutes property is between two numbers.
153156
"progressMinutes BETWEEN { $0 , $1 }", 30, 60
154157
// :remove-start:
@@ -406,7 +409,7 @@ describe("Realm Query Language Reference", () => {
406409
);
407410
expect(shallowResultLinkingObjects.length).toBe(1);
408411
expect(shallowResultLinkingObjects[0].name).toBe("Get coffee");
409-
412+
410413
const shallowResultAtLinks = realm.objects("Item").filtered(
411414
// :remove-end:
412415
// Find items that are not referenced by any project

examples/node/legacy/Examples/rql-data-models.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import Realm from "realm";
22
import { ItemModel, ProjectModel } from "./schemas/rql-data-models";
33

4+
/*
5+
DON'T UPDATE THIS FILE. DEPRECATED IN FAVOR OF V12 TESTS.
6+
Updates should be placed in the new files compatible with
7+
JSv12 and later, located at:
8+
examples/node/v12/__tests__/rql-data-models.test.js/ts
9+
*/
10+
411
describe("test models", () => {
512
let realm;
613
const config = {

examples/node/legacy/Examples/schemas/rql-data-models.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
DON'T UPDATE THIS FILE. DEPRECATED IN FAVOR OF V12 MODELS.
3+
Updates should be placed in the new file compatible with
4+
JSv12 and later, located at:
5+
examples/node/v12/__tests__/models/rql-data-models.ts
6+
*/
17
// :snippet-start: rql-data-models
28
const ItemModel = {
39
name: "Item",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Models for embedded objects & dot notation queries
2+
const Address = {
3+
name: "Address",
4+
embedded: true,
5+
properties: {
6+
name: "string",
7+
street: "string",
8+
zipcode: "int",
9+
},
10+
};
11+
12+
const Office = {
13+
name: "Office",
14+
properties: {
15+
name: "string",
16+
address: "Address",
17+
},
18+
};
19+
20+
// :snippet-start: rql-data-models
21+
const Item = {
22+
name: "Item",
23+
properties: {
24+
_id: "objectId",
25+
name: { type: "string", indexed: "full-text" },
26+
isComplete: { type: "bool", default: false },
27+
assignee: "string?",
28+
priority: { type: "int", default: 0 },
29+
progressMinutes: { type: "int", default: 0 },
30+
projects: {
31+
type: "linkingObjects",
32+
objectType: "Project",
33+
property: "items",
34+
},
35+
},
36+
primaryKey: "_id",
37+
};
38+
39+
const Project = {
40+
name: "Project",
41+
properties: {
42+
_id: "objectId",
43+
name: "string",
44+
items: "Item[]",
45+
quota: "int?",
46+
comments: "string?{}",
47+
projectLocation: "Office?",
48+
additionalInfo: "mixed",
49+
},
50+
primaryKey: "_id",
51+
};
52+
// :snippet-end:
53+
54+
export { Address, Item, Office, Project };
Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
import Realm, { BSON, ObjectSchema } from "realm";
22

3+
// Models for embedded objects & dot notation queries
4+
export class Address extends Realm.Object<Address> {
5+
name!: string;
6+
street!: string;
7+
zipcode!: number;
8+
9+
static schema: ObjectSchema = {
10+
name: "Address",
11+
embedded: true,
12+
properties: {
13+
name: "string",
14+
street: "string",
15+
zipcode: "int",
16+
},
17+
};
18+
}
19+
20+
export class Office extends Realm.Object<Office> {
21+
name!: string;
22+
address!: Address;
23+
24+
static schema: ObjectSchema = {
25+
name: "Office",
26+
properties: {
27+
name: "string",
28+
address: "Address",
29+
},
30+
};
31+
}
32+
33+
// :snippet-start: rql-data-models
334
export class Item extends Realm.Object<Item> {
435
_id!: BSON.ObjectId;
536
name!: string;
@@ -12,17 +43,11 @@ export class Item extends Realm.Object<Item> {
1243
name: "Item",
1344
properties: {
1445
_id: "objectId",
15-
name: { type:"string", indexed: "full-text" },
46+
name: { type: "string", indexed: "full-text" },
1647
isComplete: { type: "bool", default: false },
1748
assignee: "string?",
18-
priority: {
19-
type: "int",
20-
default: 0,
21-
},
22-
progressMinutes: {
23-
type: "int",
24-
default: 0,
25-
},
49+
priority: { type: "int", default: 0 },
50+
progressMinutes: { type: "int", default: 0 },
2651
projects: {
2752
type: "linkingObjects",
2853
objectType: "Project",
@@ -32,12 +57,14 @@ export class Item extends Realm.Object<Item> {
3257
primaryKey: "_id",
3358
};
3459
}
35-
3660
export class Project extends Realm.Object<Project> {
3761
_id!: BSON.ObjectId;
3862
name!: string;
39-
items!: Realm.List<Item>
40-
quota?: number
63+
items!: Realm.List<Item>;
64+
quota?: number;
65+
comments?: Realm.Dictionary<string>;
66+
projectLocation?: Office;
67+
additionalInfo!: Realm.Mixed;
4168

4269
static schema: ObjectSchema = {
4370
name: "Project",
@@ -46,7 +73,11 @@ export class Project extends Realm.Object<Project> {
4673
name: "string",
4774
items: "Item[]",
4875
quota: "int?",
76+
comments: "string?{}",
77+
projectLocation: "Office?",
78+
additionalInfo: "mixed",
4979
},
5080
primaryKey: "_id",
51-
}
52-
};
81+
};
82+
}
83+
// :snippet-end:

0 commit comments

Comments
 (0)