@@ -22,7 +22,13 @@ const db = new Polybase({ defaultNamespace: "your-namespace" });
22
22
const collectionReference = db .collection (" cities" );
23
23
24
24
async function getRecord () {
25
- const { data , block } = await collectionReference .record (" id" ).get ();
25
+ const record = await collectionReference .record (" id" ).get ();
26
+
27
+ // Get data from the record
28
+ const { data } = record; // or const data = record.data
29
+
30
+ // Record is CollectionRecordResponse instance, so you can also get again to refresh
31
+ const updatedRecord = record .get ();
26
32
}
27
33
```
28
34
@@ -74,6 +80,12 @@ const collectionReference = db.collection("cities");
74
80
75
81
export async function listRecordsWithFilter () {
76
82
const records = await collectionReference .where (" country" , " ==" , " UK" ).get ();
83
+
84
+ // Array of records is available under the data property
85
+ const { data , cursor } = records;
86
+
87
+ // Records is QueryResponse, so we can use it to get the next page of results
88
+ await records .next ();
77
89
}
78
90
79
91
```
@@ -110,3 +122,43 @@ const collectionReference = db
110
122
}
111
123
);
112
124
```
125
+
126
+ ## Pagination
127
+
128
+ You can paginate through your results using the cursor returned from the
129
+ ` .get() ` method, or by using the built-in ` .next() `
130
+
131
+ ### Pagination with cursor
132
+
133
+ Use the cursor response with ` .before() ` and ` .after() ` to paginate through
134
+ collection data.
135
+
136
+ ``` js
137
+ const db = new Polybase ({ defaultNamespace: " your-namespace" });
138
+ const collectionReference = await db .collection (" cities" );
139
+
140
+ // First page
141
+ const { data , cursor } = await collectionReference .get ();
142
+
143
+ // Next page
144
+ const next = await collectionReference .after (cursor .after ).get ();
145
+
146
+ // Previous page
147
+ const previous = await collectionReference .before (cursor .before ).get ();
148
+ ```
149
+
150
+ ### Pagination with next() or previous()
151
+
152
+ To simplify this process, a ` next() ` and ` previous() ` helper method is provided on the response.
153
+
154
+ ``` js
155
+ const db = new Polybase ({ defaultNamespace: " your-namespace" });
156
+ const collectionReference = await db .collection (" cities" );
157
+
158
+ // First page
159
+ const first = await collectionReference .get ();
160
+
161
+ // Next pages
162
+ const second = await first .next ();
163
+ const third = await second .next ();
164
+ ```
0 commit comments