@xata.io/client 0.16.1 → 0.17.1

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 CHANGED
@@ -1,5 +1,43 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.17.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#584](https://github.com/xataio/client-ts/pull/584) [`a305072`](https://github.com/xataio/client-ts/commit/a3050726517632b4975f2a2ed5f771dd247e51d5) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix issues with multiple filters
8
+
9
+ * [#249](https://github.com/xataio/client-ts/pull/249) [`7812a41`](https://github.com/xataio/client-ts/commit/7812a414b7d99e9515c0ce48a61ad7a8b84d65d0) Thanks [@xata-bot](https://github.com/xata-bot)! - API: Add first endpoints for migration requests and schema compare
10
+
11
+ - [#585](https://github.com/xataio/client-ts/pull/585) [`d4a8ced`](https://github.com/xataio/client-ts/commit/d4a8ced9c257058ed7f660e01ee5fd1da154c391) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix problem with some special characters not being URI encoded
12
+
13
+ * [#574](https://github.com/xataio/client-ts/pull/574) [`cf85b13`](https://github.com/xataio/client-ts/commit/cf85b13e1ca69e79100fd02f58d79d556012395d) Thanks [@SferaDev](https://github.com/SferaDev)! - Do not allow unknown tables on codegen output
14
+
15
+ - [#576](https://github.com/xataio/client-ts/pull/576) [`2350739`](https://github.com/xataio/client-ts/commit/2350739d3f0a176b0f1fc77b0f4f597321349726) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow sending empty, undefined or conditional filters
16
+
17
+ * [#581](https://github.com/xataio/client-ts/pull/581) [`a336e61`](https://github.com/xataio/client-ts/commit/a336e6161be04a652e6f0f0a4c2edac10d50c99e) Thanks [@SferaDev](https://github.com/SferaDev)! - Update error codes in tracing
18
+
19
+ ## 0.17.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [#563](https://github.com/xataio/client-ts/pull/563) [`26e91d1`](https://github.com/xataio/client-ts/commit/26e91d1d84df082dedd7159271fc7c27ec87fefe) Thanks [@SferaDev](https://github.com/SferaDev)! - Return nulls on operations that can fail
24
+
25
+ * [#563](https://github.com/xataio/client-ts/pull/563) [`3332d43`](https://github.com/xataio/client-ts/commit/3332d43121367f61c8d87dfb7da2af65bd1c278f) Thanks [@SferaDev](https://github.com/SferaDev)! - Return object on delete operation
26
+
27
+ ## 0.16.2
28
+
29
+ ### Patch Changes
30
+
31
+ - [#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
32
+
33
+ * [#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
34
+
35
+ - [#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
36
+
37
+ * [#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
38
+
39
+ - [#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
40
+
3
41
  ## 0.16.1
4
42
 
5
43
  ### Patch Changes
package/README.md CHANGED
@@ -12,11 +12,11 @@ This SDK has zero dependencies, so it can be used in many JavaScript runtimes in
12
12
  - [Schema-generated Client](#schema-generated-client)
13
13
  - [Schema-less Client](#schema-less-client)
14
14
  - [API Design](#api-design)
15
- - [Creating Objects](#creating-objects)
16
- - [Query a Single Object by its ID](#query-a-single-object-by-its-id)
17
- - [Querying Multiple Objects](#querying-multiple-objects)
18
- - [Updating Objects](#updating-objects)
19
- - [Deleting Objects](#deleting-objects)
15
+ - [Creating Records](#creating-records)
16
+ - [Query a Single Record by its ID](#query-a-single-record-by-its-id)
17
+ - [Querying Multiple Records](#querying-multiple-records)
18
+ - [Updating Records](#updating-records)
19
+ - [Deleting Records](#deleting-records)
20
20
  - [API Client](#api-client)
21
21
  - [Deno support](#deno-support)
22
22
 
@@ -102,7 +102,7 @@ The Xata SDK to create/read/update/delete records follows the [repository patter
102
102
 
103
103
  For example if you have a `users` table, there'll be a repository at `xata.db.users`. If you're using the schema-less client, you can also use the `xata.db.[table-name]` syntax to access the repository but without TypeScript auto-completion.
104
104
 
105
- #### Creating Objects
105
+ #### Creating Records
106
106
 
107
107
  Invoke the `create()` method in the repository. Example:
108
108
 
@@ -123,22 +123,22 @@ const user = await xata.db.users.insert('user_admin', {
123
123
  And if you want to create or insert a record with a specific ID, you can invoke `updateOrInsert()`.
124
124
 
125
125
  ```ts
126
- const user = await client.db.users.updateOrInsert('user_admin', {
126
+ const user = await xata.db.users.updateOrInsert('user_admin', {
127
127
  fullName: 'John Smith'
128
128
  });
129
129
  ```
130
130
 
131
- #### Query a Single Object by its ID
131
+ #### Query a Single Record by its ID
132
132
 
133
133
  ```ts
134
- // `user` will be null if the object cannot be found
134
+ // `user` will be null if the record cannot be found
135
135
  const user = await xata.db.users.read('rec_1234abcdef');
136
136
  ```
137
137
 
138
- #### Querying Multiple Objects
138
+ #### Querying Multiple Records
139
139
 
140
140
  ```ts
141
- // Query objects selecting all fields.
141
+ // Query records selecting all fields.
142
142
  const page = await xata.db.users.select().getPaginated();
143
143
  const user = await xata.db.users.select().getFirst();
144
144
 
@@ -146,7 +146,7 @@ const user = await xata.db.users.select().getFirst();
146
146
  const page = await xata.db.users.getPaginated();
147
147
  const user = await xata.db.users.getFirst();
148
148
 
149
- // Query objects selecting just one or more fields
149
+ // Query records selecting just one or more fields
150
150
  const page = await xata.db.users.select('email', 'profile').getPaginated();
151
151
 
152
152
  // Apply constraints
@@ -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;
@@ -205,9 +207,9 @@ for await (const records of xata.db.users.getIterator({ batchSize: 100 })) {
205
207
  }
206
208
  ```
207
209
 
208
- #### Updating Objects
210
+ #### Updating Records
209
211
 
210
- Updating an object leaves the existing instance unchanged, but returns a new object with the updated values.
212
+ Updating a record leaves the existing object unchanged, but returns a new object with the updated values.
211
213
 
212
214
  ```ts
213
215
  // Using an existing object
@@ -215,19 +217,19 @@ const updatedUser = await user.update({
215
217
  fullName: 'John Smith Jr.'
216
218
  });
217
219
 
218
- // Using an object's id
220
+ // Using a record id
219
221
  const updatedUser = await xata.db.users.update('rec_1234abcdef', {
220
222
  fullName: 'John Smith Jr.'
221
223
  });
222
224
  ```
223
225
 
224
- #### Deleting Objects
226
+ #### Deleting Records
225
227
 
226
228
  ```ts
227
229
  // Using an existing object
228
230
  await user.delete();
229
231
 
230
- // Using an object's id
232
+ // Using a record id
231
233
  await xata.db.users.delete('rec_1234abcdef');
232
234
  ```
233
235
 
@@ -244,22 +246,22 @@ const api = new XataApiClient({ apiKey: process.env.XATA_API_KEY });
244
246
  Once you have initialized the API client, the operations are organized following the same hiearchy as in the [official documentation](https://docs.xata.io). You have different namespaces for each entity (ie. `workspaces`, `databases`, `tables`, `branches`, `users`, `records`...).
245
247
 
246
248
  ```ts
247
- const { id: workspace } = await client.workspaces.createWorkspace({ name: 'example', slug: 'example' });
248
- const { databaseName } = await client.databases.createDatabase(workspace, 'database');
249
+ const { id: workspace } = await api.workspaces.createWorkspace({ name: 'example', slug: 'example' });
250
+ const { databaseName } = await api.databases.createDatabase(workspace, 'database');
249
251
 
250
- await client.branches.createBranch(workspace, databaseName, 'branch');
251
- await client.tables.createTable(workspace, databaseName, 'branch', 'table');
252
- await client.tables.setTableSchema(workspace, databaseName, 'branch', 'table', {
252
+ await api.branches.createBranch(workspace, databaseName, 'branch');
253
+ await api.tables.createTable(workspace, databaseName, 'branch', 'table');
254
+ await api.tables.setTableSchema(workspace, databaseName, 'branch', 'table', {
253
255
  columns: [{ name: 'email', type: 'string' }]
254
256
  });
255
257
 
256
- const { id: recordId } = await client.records.insertRecord(workspace, databaseName, 'branch', 'table', {
258
+ const { id: recordId } = await api.records.insertRecord(workspace, databaseName, 'branch', 'table', {
257
259
  email: 'example@foo.bar'
258
260
  });
259
261
 
260
- const record = await client.records.getRecord(workspace, databaseName, 'branch', 'table', recordId);
262
+ const record = await api.records.getRecord(workspace, databaseName, 'branch', 'table', recordId);
261
263
 
262
- await client.workspaces.deleteWorkspace(workspace);
264
+ await api.workspaces.deleteWorkspace(workspace);
263
265
  ```
264
266
 
265
267
  ## Deno support
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 some records in the query results.
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
 
@@ -375,10 +396,10 @@ for await (const users of xata.db.users.getIterator({ batchSize: 50 })) {
375
396
 
376
397
  We expose some helper variables of the API limits when paginating:
377
398
 
378
- - `PAGINATION_MAX_SIZE`: Maximum page size.
379
- - `PAGINATION_DEFAULT_SIZE`: Default page size.
380
- - `PAGINATION_MAX_OFFSET`: Maximum offset.
381
- - `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).
382
403
 
383
404
  You can use these variables if you implement your own pagination mechanism, as they will be updated when our API limits are updated.
384
405