@xata.io/client 0.0.0-alpha.vf603f80 → 0.0.0-alpha.vf6b372c
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 +134 -0
- package/README.md +30 -28
- package/Usage.md +62 -6
- package/dist/index.cjs +1835 -752
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4628 -1225
- package/dist/index.mjs +1800 -753
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,139 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.18.6
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#662](https://github.com/xataio/client-ts/pull/662) [`4a41680`](https://github.com/xataio/client-ts/commit/4a416803761a1c944ef9a76b794020ead6c8f477) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove wildcard columns from sorting and filtering
|
8
|
+
|
9
|
+
- [#303](https://github.com/xataio/client-ts/pull/303) [`ad0cccb`](https://github.com/xataio/client-ts/commit/ad0cccb11cd4f9bb4bd7e44672d3375821e700fe) Thanks [@gimenete](https://github.com/gimenete)! - Add profiles for host parsing
|
10
|
+
|
11
|
+
- [#662](https://github.com/xataio/client-ts/pull/662) [`e1d6add`](https://github.com/xataio/client-ts/commit/e1d6addf84c55648bc0d908887b6bd020b429801) Thanks [@SferaDev](https://github.com/SferaDev)! - Add aggregations support to the SDK
|
12
|
+
|
13
|
+
- [#662](https://github.com/xataio/client-ts/pull/662) [`4a41680`](https://github.com/xataio/client-ts/commit/4a416803761a1c944ef9a76b794020ead6c8f477) Thanks [@SferaDev](https://github.com/SferaDev)! - Add summarize endpoints to SDK
|
14
|
+
|
15
|
+
## 0.18.5
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- [#656](https://github.com/xataio/client-ts/pull/656) [`2dc2f5a`](https://github.com/xataio/client-ts/commit/2dc2f5a45529b2ace9127d963fb30214298da2e0) Thanks [@SferaDev](https://github.com/SferaDev)! - Broaden type for AbortSignal
|
20
|
+
|
21
|
+
## 0.18.4
|
22
|
+
|
23
|
+
### Patch Changes
|
24
|
+
|
25
|
+
- [#650](https://github.com/xataio/client-ts/pull/650) [`b8d441f`](https://github.com/xataio/client-ts/commit/b8d441f80867322f41989d52c94bba230632782b) Thanks [@xata-bot](https://github.com/xata-bot)! - API: Rename listMigrationRequests to queryMigrationRequests
|
26
|
+
|
27
|
+
## 0.18.3
|
28
|
+
|
29
|
+
### Patch Changes
|
30
|
+
|
31
|
+
- [#639](https://github.com/xataio/client-ts/pull/639) [`50fb3c0`](https://github.com/xataio/client-ts/commit/50fb3c0a1cffd03a16cc8b1b21454ea816f2edbb) Thanks [@SferaDev](https://github.com/SferaDev)! - Do not return null for columns not selected
|
32
|
+
|
33
|
+
## 0.18.2
|
34
|
+
|
35
|
+
### Patch Changes
|
36
|
+
|
37
|
+
- [#635](https://github.com/xataio/client-ts/pull/635) [`713f9b2`](https://github.com/xataio/client-ts/commit/713f9b2773be99c17d3fcb663e24fe096fa3da48) Thanks [@SferaDev](https://github.com/SferaDev)! - [Search] Add target columns
|
38
|
+
|
39
|
+
## 0.18.1
|
40
|
+
|
41
|
+
### Patch Changes
|
42
|
+
|
43
|
+
- [#627](https://github.com/xataio/client-ts/pull/627) [`ad0a5b4`](https://github.com/xataio/client-ts/commit/ad0a5b4bc87b82fdc10008a8ea324a8ca783e678) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix some cases where filters on link and multiple column types are not working
|
44
|
+
|
45
|
+
## 0.18.0
|
46
|
+
|
47
|
+
### Minor Changes
|
48
|
+
|
49
|
+
- [#562](https://github.com/xataio/client-ts/pull/562) [`699beb4`](https://github.com/xataio/client-ts/commit/699beb4bbf21cffa001d3f88a03246980e30250b) Thanks [@SferaDev](https://github.com/SferaDev)! - Return null on nullable columns
|
50
|
+
|
51
|
+
### Patch Changes
|
52
|
+
|
53
|
+
- [#583](https://github.com/xataio/client-ts/pull/583) [`330b076`](https://github.com/xataio/client-ts/commit/330b076a0781e3576c82afab76e3fb2a64f2e041) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for unique columns
|
54
|
+
|
55
|
+
- [#598](https://github.com/xataio/client-ts/pull/598) [`c3dfb4b`](https://github.com/xataio/client-ts/commit/c3dfb4babc990634b9e9747616ed93223178a2e7) Thanks [@SferaDev](https://github.com/SferaDev)! - API: Add patch database metadata endpoint
|
56
|
+
|
57
|
+
- [#602](https://github.com/xataio/client-ts/pull/602) [`74b17aa`](https://github.com/xataio/client-ts/commit/74b17aaedc0dbdd79bfdcb182b2e70b61f98f5a5) Thanks [@gimenete](https://github.com/gimenete)! - API: Make workspace slug optional on create
|
58
|
+
|
59
|
+
- [#615](https://github.com/xataio/client-ts/pull/615) [`83f20cd`](https://github.com/xataio/client-ts/commit/83f20cdbe53706c16016c4db3f318e679b24ec86) Thanks [@SferaDev](https://github.com/SferaDev)! - Make `getMany` return more items than max pagination size
|
60
|
+
|
61
|
+
- [#562](https://github.com/xataio/client-ts/pull/562) [`addfcc6`](https://github.com/xataio/client-ts/commit/addfcc67fca663defdd340111ea09c9188bad3ab) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `orThrows` methods that instead of returning null, throw an exception.
|
62
|
+
|
63
|
+
- [#583](https://github.com/xataio/client-ts/pull/583) [`eb7ba59`](https://github.com/xataio/client-ts/commit/eb7ba594be2a1f0ab90956836bbeb912e188a46d) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for non nullable columns
|
64
|
+
|
65
|
+
- [#612](https://github.com/xataio/client-ts/pull/612) [`f1a0742`](https://github.com/xataio/client-ts/commit/f1a0742a04e1aefab14f46371a04a41069faec01) Thanks [@xata-bot](https://github.com/xata-bot)! - API: Add summarize table endpoint
|
66
|
+
|
67
|
+
## 0.17.1
|
68
|
+
|
69
|
+
### Patch Changes
|
70
|
+
|
71
|
+
- [#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
|
72
|
+
|
73
|
+
* [#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
|
74
|
+
|
75
|
+
- [#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
|
76
|
+
|
77
|
+
* [#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
|
78
|
+
|
79
|
+
- [#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
|
80
|
+
|
81
|
+
* [#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
|
82
|
+
|
83
|
+
## 0.17.0
|
84
|
+
|
85
|
+
### Minor Changes
|
86
|
+
|
87
|
+
- [#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
|
88
|
+
|
89
|
+
* [#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
|
90
|
+
|
91
|
+
## 0.16.2
|
92
|
+
|
93
|
+
### Patch Changes
|
94
|
+
|
95
|
+
- [#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
|
96
|
+
|
97
|
+
* [#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
|
98
|
+
|
99
|
+
- [#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
|
100
|
+
|
101
|
+
* [#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
|
102
|
+
|
103
|
+
- [#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
|
104
|
+
|
105
|
+
## 0.16.1
|
106
|
+
|
107
|
+
### Patch Changes
|
108
|
+
|
109
|
+
- [#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
|
110
|
+
|
111
|
+
* [#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
|
112
|
+
|
113
|
+
- [#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
|
114
|
+
|
115
|
+
## 0.16.0
|
116
|
+
|
117
|
+
### Minor Changes
|
118
|
+
|
119
|
+
- [#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
|
120
|
+
|
121
|
+
* [#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
|
122
|
+
|
123
|
+
### Patch Changes
|
124
|
+
|
125
|
+
- [#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
|
126
|
+
|
127
|
+
* [#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
|
128
|
+
|
129
|
+
## 0.15.0
|
130
|
+
|
131
|
+
### Patch Changes
|
132
|
+
|
133
|
+
- [#496](https://github.com/xataio/client-ts/pull/496) [`e923d11`](https://github.com/xataio/client-ts/commit/e923d11fe357519dc4ca3ae722670e6e70ccd1c6) Thanks [@gimenete](https://github.com/gimenete)! - Ignore git output in Xata client
|
134
|
+
|
135
|
+
* [#481](https://github.com/xataio/client-ts/pull/481) [`599b52c`](https://github.com/xataio/client-ts/commit/599b52c3090222eedef85d1ad1e907874cd3e801) Thanks [@xata-bot](https://github.com/xata-bot)! - Add updateWorkspaceMemberInvite API method
|
136
|
+
|
3
137
|
## 0.14.0
|
4
138
|
|
5
139
|
### Minor 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
|
16
|
-
- [Query a Single
|
17
|
-
- [Querying Multiple
|
18
|
-
- [Updating
|
19
|
-
- [Deleting
|
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
|
105
|
+
#### Creating Records
|
106
106
|
|
107
107
|
Invoke the `create()` method in the repository. Example:
|
108
108
|
|
@@ -112,33 +112,33 @@ const user = await xata.db.users.create({
|
|
112
112
|
});
|
113
113
|
```
|
114
114
|
|
115
|
-
If you want to create a record with a specific ID, you can
|
115
|
+
If you want to create a record with a specific ID, you can provide the id as parameter to the `create()` method.
|
116
116
|
|
117
117
|
```ts
|
118
|
-
const user = await xata.db.users.
|
118
|
+
const user = await xata.db.users.create('user_admin', {
|
119
119
|
fullName: 'John Smith'
|
120
120
|
});
|
121
121
|
```
|
122
122
|
|
123
|
-
And if you want to create or
|
123
|
+
And if you want to create or update a record with a specific ID, you can invoke `createOrUpdate()` with an id parameter.
|
124
124
|
|
125
125
|
```ts
|
126
|
-
const user = await
|
126
|
+
const user = await xata.db.users.createOrUpdate('user_admin', {
|
127
127
|
fullName: 'John Smith'
|
128
128
|
});
|
129
129
|
```
|
130
130
|
|
131
|
-
#### Query a Single
|
131
|
+
#### Query a Single Record by its ID
|
132
132
|
|
133
133
|
```ts
|
134
|
-
// `user` will be null if the
|
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
|
138
|
+
#### Querying Multiple Records
|
139
139
|
|
140
140
|
```ts
|
141
|
-
// Query
|
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
|
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
|
210
|
+
#### Updating Records
|
209
211
|
|
210
|
-
Updating
|
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
|
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
|
226
|
+
#### Deleting Records
|
225
227
|
|
226
228
|
```ts
|
227
229
|
// Using an existing object
|
228
230
|
await user.delete();
|
229
231
|
|
230
|
-
// Using
|
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
|
248
|
-
const { databaseName } = await
|
249
|
+
const { id: workspace } = await api.workspaces.createWorkspace({ name: 'example' });
|
250
|
+
const { databaseName } = await api.database.createDatabase(workspace, 'database', { region: 'eu-west-1' });
|
249
251
|
|
250
|
-
await
|
251
|
-
await
|
252
|
-
await
|
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
|
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
|
262
|
+
const record = await api.records.getRecord(workspace, databaseName, 'branch', 'table', recordId);
|
261
263
|
|
262
|
-
await
|
264
|
+
await api.workspaces.deleteWorkspace(workspace);
|
263
265
|
```
|
264
266
|
|
265
267
|
## Deno support
|
package/Usage.md
CHANGED
@@ -38,8 +38,31 @@ 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
|
+
Both the `getAll()` and `getMany()` will produce multiple requests to the server if the query should return more than the maximum page size. We perform the minimum number of requests to get the desired number of records.
|
45
|
+
|
46
|
+
All these methods allow customising its filters, column selection, column ordering, pagination or cache TTL. For example:
|
47
|
+
|
48
|
+
```ts
|
49
|
+
// First item sorting by name
|
50
|
+
const user = await xata.db.users.getFirst({ sort: 'name' });
|
51
|
+
|
52
|
+
// Get first 50 items but ignore the first one
|
53
|
+
const users = await xata.db.users.getMany({ pagination: { size: 50, offset: 1 } });
|
54
|
+
|
55
|
+
// Get page of 100 items where name contains "foo"
|
56
|
+
const page = await xata.db.users.getPaginated({ filter: { name: { $contains: 'foo' } }, pagination: { size: 100 } });
|
57
|
+
|
58
|
+
// Get all admin users and cache the result for 5 minutes
|
59
|
+
const user = await xata.db.users.filter('role', 'admin').getAll({ cache: 5 * 60 * 1000 });
|
60
|
+
|
61
|
+
// Overwrite values set in a query
|
62
|
+
const query = xata.db.users.filter('role', 'admin').select(['name']);
|
63
|
+
const adminUsers = await query.getAll();
|
64
|
+
const firstAdminUserWithEmail = await query.getFirst({ columns: ['name', 'email'] });
|
65
|
+
```
|
43
66
|
|
44
67
|
Since the [`Repository`](#repository) class implements the `Query` interface, you can use it to query and paginate the records in the table too.
|
45
68
|
|
@@ -155,6 +178,13 @@ const user = await xata.db.users.read(object1);
|
|
155
178
|
const users = await xata.db.users.read([object1, object2]);
|
156
179
|
```
|
157
180
|
|
181
|
+
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.
|
182
|
+
|
183
|
+
```ts
|
184
|
+
const user = await xata.db.users.read('rec_1234abcdef', ['fullName', 'team.name']);
|
185
|
+
const users = await xata.db.users.read(['rec_1234abcdef', 'rec_5678defgh'], ['fullName', 'team.name']);
|
186
|
+
```
|
187
|
+
|
158
188
|
### Creating Records
|
159
189
|
|
160
190
|
Both the `create()` and `createOrUpdate()` methods can be used to create a new record.
|
@@ -202,6 +232,19 @@ const users = await xata.db.users.createOrUpdate([
|
|
202
232
|
]);
|
203
233
|
```
|
204
234
|
|
235
|
+
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.
|
236
|
+
|
237
|
+
```ts
|
238
|
+
const user = await xata.db.users.create('user_admin', { fullName: 'John Smith' }, ['fullName', 'team.name']);
|
239
|
+
const users = await xata.db.users.createOrUpdate(
|
240
|
+
[
|
241
|
+
{ id: 'user_admin', fullName: 'John Smith' },
|
242
|
+
{ id: 'user_manager', fullName: 'Jane Doe' }
|
243
|
+
],
|
244
|
+
['fullName', 'team.name']
|
245
|
+
);
|
246
|
+
```
|
247
|
+
|
205
248
|
### Updating records
|
206
249
|
|
207
250
|
The `update()` method can be used to update an existing record. It will throw an `Error` if the record cannot be found.
|
@@ -225,6 +268,12 @@ const users = await xata.db.users.update([
|
|
225
268
|
]);
|
226
269
|
```
|
227
270
|
|
271
|
+
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.
|
272
|
+
|
273
|
+
```ts
|
274
|
+
const user = await xata.db.users.update('rec_1234abcdef', { fullName: 'John Smith' }, ['fullName', 'team.name']);
|
275
|
+
```
|
276
|
+
|
228
277
|
### Deleting Records
|
229
278
|
|
230
279
|
The `delete()` method can be used to delete an existing record. It will throw an `Error` if the record cannot be found.
|
@@ -349,10 +398,10 @@ for await (const users of xata.db.users.getIterator({ batchSize: 50 })) {
|
|
349
398
|
|
350
399
|
We expose some helper variables of the API limits when paginating:
|
351
400
|
|
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.
|
401
|
+
- `PAGINATION_MAX_SIZE`: Maximum page size (200).
|
402
|
+
- `PAGINATION_DEFAULT_SIZE`: Default page size (20).
|
403
|
+
- `PAGINATION_MAX_OFFSET`: Maximum offset (800).
|
404
|
+
- `PAGINATION_DEFAULT_OFFSET`: Default offset (0).
|
356
405
|
|
357
406
|
You can use these variables if you implement your own pagination mechanism, as they will be updated when our API limits are updated.
|
358
407
|
|
@@ -373,6 +422,13 @@ user?.update({ fullName: 'John Doe' }); // Partially updates the record
|
|
373
422
|
user?.delete(); // Deletes the record
|
374
423
|
```
|
375
424
|
|
425
|
+
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.
|
426
|
+
|
427
|
+
```ts
|
428
|
+
const user = await xata.db.users.read('rec_1234abcdef');
|
429
|
+
user?.read(['fullName', 'team.name']); // Reads the record again with the `fullName` and `team.name` columns
|
430
|
+
```
|
431
|
+
|
376
432
|
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
433
|
|
378
434
|
```ts
|