@xata.io/client 0.15.0 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +2 -0
- package/Usage.md +60 -6
- package/dist/index.cjs +477 -300
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +533 -136
- package/dist/index.mjs +466 -301
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,43 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.16.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#541](https://github.com/xataio/client-ts/pull/541) [`c74467c`](https://github.com/xataio/client-ts/commit/c74467caeff4e3d60d0981a173b462e970c6c1fc) Thanks [@SferaDev](https://github.com/SferaDev)! - Add tracing with open telemetry
|
8
|
+
|
9
|
+
* [#551](https://github.com/xataio/client-ts/pull/551) [`ee72bfe`](https://github.com/xataio/client-ts/commit/ee72bfef34765374ec66c7edaa6b5508c3f8e8dc) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix filter operators and dates
|
10
|
+
|
11
|
+
- [#552](https://github.com/xataio/client-ts/pull/552) [`e88effa`](https://github.com/xataio/client-ts/commit/e88effa00f8c2c0e24ec8cd60fb21859ac236191) Thanks [@SferaDev](https://github.com/SferaDev)! - Update error message for required settings
|
12
|
+
|
13
|
+
* [#551](https://github.com/xataio/client-ts/pull/551) [`33293b3`](https://github.com/xataio/client-ts/commit/33293b3509d984bb9b1af457c96260d43f398efe) Thanks [@SferaDev](https://github.com/SferaDev)! - Add aliases for some operators
|
14
|
+
|
15
|
+
- [#534](https://github.com/xataio/client-ts/pull/534) [`efc09b4`](https://github.com/xataio/client-ts/commit/efc09b420a25253b428662c2eec40ff3bc36ce79) Thanks [@SferaDev](https://github.com/SferaDev)! - Make sort direction optional
|
16
|
+
|
17
|
+
## 0.16.1
|
18
|
+
|
19
|
+
### Patch Changes
|
20
|
+
|
21
|
+
- [#531](https://github.com/xataio/client-ts/pull/531) [`e33d8fb`](https://github.com/xataio/client-ts/commit/e33d8fbca264d3ab1597ed698d5e79484dcba8a3) Thanks [@xata-bot](https://github.com/xata-bot)! - Add new method to list database metadata in the API client
|
22
|
+
|
23
|
+
* [#524](https://github.com/xataio/client-ts/pull/524) [`a3b1044`](https://github.com/xataio/client-ts/commit/a3b1044038c4ae73b4aacaa112818e69b7d380e1) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose internal config information
|
24
|
+
|
25
|
+
- [#525](https://github.com/xataio/client-ts/pull/525) [`5f0f2c2`](https://github.com/xataio/client-ts/commit/5f0f2c2bb42da360e810f0a61ce360f8f8b07a04) Thanks [@xata-bot](https://github.com/xata-bot)! - Update dependencies
|
26
|
+
|
27
|
+
## 0.16.0
|
28
|
+
|
29
|
+
### Minor Changes
|
30
|
+
|
31
|
+
- [#485](https://github.com/xataio/client-ts/pull/485) [`a9cbb26`](https://github.com/xataio/client-ts/commit/a9cbb263fbca47cb91a827db252d95a5bb4079a6) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow selecting columns with record operations
|
32
|
+
|
33
|
+
* [#485](https://github.com/xataio/client-ts/pull/485) [`7e04a3d`](https://github.com/xataio/client-ts/commit/7e04a3d1c51958a44f687a0036ead8bb3f5a2dfb) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove record cache
|
34
|
+
|
35
|
+
### Patch Changes
|
36
|
+
|
37
|
+
- [#503](https://github.com/xataio/client-ts/pull/503) [`6a96ea5`](https://github.com/xataio/client-ts/commit/6a96ea5da4c5b7ca9a99b57ebbce8d6766b5d4d8) Thanks [@xata-bot](https://github.com/xata-bot)! - Update API response types for create of tables and branches
|
38
|
+
|
39
|
+
* [#421](https://github.com/xataio/client-ts/pull/421) [`43f2560`](https://github.com/xataio/client-ts/commit/43f25605ddd0d2fd514a1542a14389d28955c500) Thanks [@SferaDev](https://github.com/SferaDev)! - Add search boosters and allow prefix search
|
40
|
+
|
3
41
|
## 0.15.0
|
4
42
|
|
5
43
|
### Patch Changes
|
package/README.md
CHANGED
@@ -158,6 +158,8 @@ const page = await xata.db.users.sort('full_name', 'asc').getPaginated();
|
|
158
158
|
|
159
159
|
Query operations (`select()`, `filter()`, `sort()`) return a `Query` object. These objects are immutable. You can add additional constraints, `sort`, etc. by calling their methods, and a new query will be returned. In order to finally make a query to the database you'll invoke `getPaginated()`, `getMany()`, `getAll()`, or `getFirst()`.
|
160
160
|
|
161
|
+
To learn the differences between these methods, see the [reference](https://docs.xata.io/sdk/reference#query).
|
162
|
+
|
161
163
|
```ts
|
162
164
|
// Operators that combine multiple conditions can be deconstructed
|
163
165
|
const { filter, any, all, not, sort } = xata.db.users;
|
package/Usage.md
CHANGED
@@ -38,8 +38,29 @@ To get a collection of records, you can use the `Query` object. It provides the
|
|
38
38
|
|
39
39
|
- `getFirst()`: returns the first record in the query results.
|
40
40
|
- `getPaginated()`: returns a page of records in the query results.
|
41
|
-
- `getAll()`: returns all the records in the query results.
|
42
|
-
- `getMany()`: returns an array of
|
41
|
+
- `getAll()`: returns all the records in the query results by making multiple requests to iterate over all the pages which exist. If the query is not filtered and the table is a large dataset, this operation can affect the performance.
|
42
|
+
- `getMany()`: returns an array with a subset of the first results in the query. The default [pagination](#page) size (20) is used and can be customised by passing a different `{ pagination: { size: number } }` in its options. To learn more about default values, see [helper variables](#helper-variables).
|
43
|
+
|
44
|
+
All these methods allow customising its filters, column selection, column ordering, pagination or cache TTL. For example:
|
45
|
+
|
46
|
+
```ts
|
47
|
+
// First item sorting by name
|
48
|
+
const user = await xata.db.users.getFirst({ sort: 'name' });
|
49
|
+
|
50
|
+
// Get first 50 items but ignore the first one
|
51
|
+
const users = await xata.db.users.getMany({ pagination: { size: 50, offset: 1 } });
|
52
|
+
|
53
|
+
// Get page of 100 items where name contains "foo"
|
54
|
+
const page = await xata.db.users.getPaginated({ filter: { name: { $contains: 'foo' } }, pagination: { size: 100 } });
|
55
|
+
|
56
|
+
// Get all admin users and cache the result for 5 minutes
|
57
|
+
const user = await xata.db.users.filter('role', 'admin').getAll({ cache: 5 * 60 * 1000 });
|
58
|
+
|
59
|
+
// Overwrite values set in a query
|
60
|
+
const query = xata.db.users.filter('role', 'admin').select(['name']);
|
61
|
+
const adminUsers = await query.getAll();
|
62
|
+
const firstAdminUserWithEmail = await query.getFirst({ columns: ['name', 'email'] });
|
63
|
+
```
|
43
64
|
|
44
65
|
Since the [`Repository`](#repository) class implements the `Query` interface, you can use it to query and paginate the records in the table too.
|
45
66
|
|
@@ -155,6 +176,13 @@ const user = await xata.db.users.read(object1);
|
|
155
176
|
const users = await xata.db.users.read([object1, object2]);
|
156
177
|
```
|
157
178
|
|
179
|
+
By default an object with the first level properties is returned. If you want to reduce or expand its columns, you can pass an array of columns to the `read()` method.
|
180
|
+
|
181
|
+
```ts
|
182
|
+
const user = await xata.db.users.read('rec_1234abcdef', ['fullName', 'team.name']);
|
183
|
+
const users = await xata.db.users.read(['rec_1234abcdef', 'rec_5678defgh'], ['fullName', 'team.name']);
|
184
|
+
```
|
185
|
+
|
158
186
|
### Creating Records
|
159
187
|
|
160
188
|
Both the `create()` and `createOrUpdate()` methods can be used to create a new record.
|
@@ -202,6 +230,19 @@ const users = await xata.db.users.createOrUpdate([
|
|
202
230
|
]);
|
203
231
|
```
|
204
232
|
|
233
|
+
By default, the `create` and `createOrUpdate` methods will return the created record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `create` or `createOrUpdate` method.
|
234
|
+
|
235
|
+
```ts
|
236
|
+
const user = await xata.db.users.create('user_admin', { fullName: 'John Smith' }, ['fullName', 'team.name']);
|
237
|
+
const users = await xata.db.users.createOrUpdate(
|
238
|
+
[
|
239
|
+
{ id: 'user_admin', fullName: 'John Smith' },
|
240
|
+
{ id: 'user_manager', fullName: 'Jane Doe' }
|
241
|
+
],
|
242
|
+
['fullName', 'team.name']
|
243
|
+
);
|
244
|
+
```
|
245
|
+
|
205
246
|
### Updating records
|
206
247
|
|
207
248
|
The `update()` method can be used to update an existing record. It will throw an `Error` if the record cannot be found.
|
@@ -225,6 +266,12 @@ const users = await xata.db.users.update([
|
|
225
266
|
]);
|
226
267
|
```
|
227
268
|
|
269
|
+
By default, the `update` method will return the updated record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `update` method.
|
270
|
+
|
271
|
+
```ts
|
272
|
+
const user = await xata.db.users.update('rec_1234abcdef', { fullName: 'John Smith' }, ['fullName', 'team.name']);
|
273
|
+
```
|
274
|
+
|
228
275
|
### Deleting Records
|
229
276
|
|
230
277
|
The `delete()` method can be used to delete an existing record. It will throw an `Error` if the record cannot be found.
|
@@ -349,10 +396,10 @@ for await (const users of xata.db.users.getIterator({ batchSize: 50 })) {
|
|
349
396
|
|
350
397
|
We expose some helper variables of the API limits when paginating:
|
351
398
|
|
352
|
-
- `PAGINATION_MAX_SIZE`: Maximum page size.
|
353
|
-
- `PAGINATION_DEFAULT_SIZE`: Default page size.
|
354
|
-
- `PAGINATION_MAX_OFFSET`: Maximum offset.
|
355
|
-
- `PAGINATION_DEFAULT_OFFSET`: Default offset.
|
399
|
+
- `PAGINATION_MAX_SIZE`: Maximum page size (200).
|
400
|
+
- `PAGINATION_DEFAULT_SIZE`: Default page size (20).
|
401
|
+
- `PAGINATION_MAX_OFFSET`: Maximum offset (800).
|
402
|
+
- `PAGINATION_DEFAULT_OFFSET`: Default offset (0).
|
356
403
|
|
357
404
|
You can use these variables if you implement your own pagination mechanism, as they will be updated when our API limits are updated.
|
358
405
|
|
@@ -373,6 +420,13 @@ user?.update({ fullName: 'John Doe' }); // Partially updates the record
|
|
373
420
|
user?.delete(); // Deletes the record
|
374
421
|
```
|
375
422
|
|
423
|
+
The `read` and `update` methods return the updated record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `read` and `update` methods.
|
424
|
+
|
425
|
+
```ts
|
426
|
+
const user = await xata.db.users.read('rec_1234abcdef');
|
427
|
+
user?.read(['fullName', 'team.name']); // Reads the record again with the `fullName` and `team.name` columns
|
428
|
+
```
|
429
|
+
|
376
430
|
If the table contains a link property, it will be represented as a `Link` object containing its `id` property and methods to read again or update the linked record.
|
377
431
|
|
378
432
|
```ts
|