@xata.io/client 0.0.0-alpha.vf61048f → 0.0.0-alpha.vf63fddb

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @xata.io/client@0.21.6 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.26.4 add-version /home/runner/work/client-ts/client-ts/packages/client
3
3
  > node ../../scripts/add-version-file.mjs
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- > @xata.io/client@0.21.6 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.26.4 build /home/runner/work/client-ts/client-ts/packages/client
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
@@ -7,7 +7,7 @@
7
7
  created dist/index.cjs in 1s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 853ms
10
+ created dist/index.mjs in 751ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 6.3s
13
+ created dist/index.d.ts in 8.3s
package/CHANGELOG.md CHANGED
@@ -1,14 +1,206 @@
1
1
  # @xata.io/client
2
2
 
3
- ## 0.0.0-alpha.vf61048f
3
+ ## 0.0.0-alpha.vf63fddb
4
+
5
+ ### Patch Changes
6
+
7
+ - Force canary build
8
+
9
+ ## 0.26.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1160](https://github.com/xataio/client-ts/pull/1160) [`7166797c`](https://github.com/xataio/client-ts/commit/7166797c28839198d20a9115d0414cebc2fed39b) Thanks [@SferaDev](https://github.com/SferaDev)! - [Files] Return file id on array
14
+
15
+ - [#1156](https://github.com/xataio/client-ts/pull/1156) [`b85df75f`](https://github.com/xataio/client-ts/commit/b85df75f2f466762a8b3d9824c9292c7e3db03fd) Thanks [@SferaDev](https://github.com/SferaDev)! - [Files] Add download transformation
16
+
17
+ ## 0.26.3
18
+
19
+ ### Patch Changes
20
+
21
+ - [#1144](https://github.com/xataio/client-ts/pull/1144) [`4910dce2`](https://github.com/xataio/client-ts/commit/4910dce29d3cc17d13aadf32e4eb476ffb571fad) Thanks [@SferaDev](https://github.com/SferaDev)! - Support for JSON and Revlinks
22
+
23
+ ## 0.26.2
24
+
25
+ ### Patch Changes
26
+
27
+ - [#1147](https://github.com/xataio/client-ts/pull/1147) [`22fccb51`](https://github.com/xataio/client-ts/commit/22fccb51709749c319897702c15749b74ce4b820) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose metadataSignedUrl
28
+
29
+ ## 0.26.1
30
+
31
+ ### Patch Changes
32
+
33
+ - [#1139](https://github.com/xataio/client-ts/pull/1139) [`922e6e54`](https://github.com/xataio/client-ts/commit/922e6e54e8b31641770a36b6b4ff8f4fa65d304d) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix scenario with merging existing transformations
34
+
35
+ - [#1140](https://github.com/xataio/client-ts/pull/1140) [`13f6f3e4`](https://github.com/xataio/client-ts/commit/13f6f3e4b1a2f925d50a5380b62ef1057f5c3893) Thanks [@SferaDev](https://github.com/SferaDev)! - Add metadata url for transformations
36
+
37
+ - [#1136](https://github.com/xataio/client-ts/pull/1136) [`f02fc165`](https://github.com/xataio/client-ts/commit/f02fc165bf6558e4377eb9f8e1d0f4222f004c70) Thanks [@SferaDev](https://github.com/SferaDev)! - Fixes for Blob files in binary APIs
38
+
39
+ ## 0.26.0
4
40
 
5
41
  ### Minor Changes
6
42
 
7
- - [#852](https://github.com/xataio/client-ts/pull/852) [`b2a4def4`](https://github.com/xataio/client-ts/commit/b2a4def4baf3eb18cd323895635e0bccb7f876f4) Thanks [@SferaDev](https://github.com/SferaDev)! - [BREAKING CHANGE] Reduce column selection depth
43
+ - [#893](https://github.com/xataio/client-ts/pull/893) [`6ec862f8`](https://github.com/xataio/client-ts/commit/6ec862f8f799eb692f62be79dd0b613b83a34780) Thanks [@SferaDev](https://github.com/SferaDev)! - Add SQL plugin
8
44
 
9
45
  ### Patch Changes
10
46
 
11
- - Force canary build
47
+ - [#1134](https://github.com/xataio/client-ts/pull/1134) [`0c0149ad`](https://github.com/xataio/client-ts/commit/0c0149ad1ee3f7c0fe9d31030552b022c907edb0) Thanks [@SferaDev](https://github.com/SferaDev)! - Make transformImage accept object-shaped parameters
48
+
49
+ ## 0.25.3
50
+
51
+ ### Patch Changes
52
+
53
+ - [#1131](https://github.com/xataio/client-ts/pull/1131) [`3b9e1984`](https://github.com/xataio/client-ts/commit/3b9e1984329cd0e9f885f6af4155cc85ab61ba41) Thanks [@xata-bot](https://github.com/xata-bot)! - Add json type for columns
54
+
55
+ ## 0.25.2
56
+
57
+ ### Patch Changes
58
+
59
+ - [#1111](https://github.com/xataio/client-ts/pull/1111) [`9d1ace5f`](https://github.com/xataio/client-ts/commit/9d1ace5f12788755f3150449120b27cd030af3a9) Thanks [@SferaDev](https://github.com/SferaDev)! - Export file helpers
60
+
61
+ - [#1114](https://github.com/xataio/client-ts/pull/1114) [`f6665593`](https://github.com/xataio/client-ts/commit/f6665593c301dc9400834cbd68ae32b92bbdea5d) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix warning with default env branch
62
+
63
+ ## 0.25.1
64
+
65
+ ### Patch Changes
66
+
67
+ - [#1101](https://github.com/xataio/client-ts/pull/1101) [`321c33ff`](https://github.com/xataio/client-ts/commit/321c33ff684c416a6cc813be2a970fd8f826b885) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bug with cancellable timeouts
68
+
69
+ ## 0.25.0
70
+
71
+ ### Minor Changes
72
+
73
+ - [#1041](https://github.com/xataio/client-ts/pull/1041) [`ac3b968f`](https://github.com/xataio/client-ts/commit/ac3b968f7ca476f2c82b1b2719d020fbd7164f38) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for files and attachments
74
+
75
+ ### Patch Changes
76
+
77
+ - [#1024](https://github.com/xataio/client-ts/pull/1024) [`aef9c834`](https://github.com/xataio/client-ts/commit/aef9c834a850494020e7585cb4ce67b446f9ccfc) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix type inconsistency with `xata` internal property
78
+
79
+ - [#1085](https://github.com/xataio/client-ts/pull/1085) [`bcce0d3b`](https://github.com/xataio/client-ts/commit/bcce0d3b0b53468937accd4fee3b5485c35f69ad) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for sessions in ask endpoint
80
+
81
+ - [#1067](https://github.com/xataio/client-ts/pull/1067) [`c1f2d264`](https://github.com/xataio/client-ts/commit/c1f2d2649e077cdffae97c90b9d2b1c75d6858fb) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix error 400 with partial filters
82
+
83
+ - [#1071](https://github.com/xataio/client-ts/pull/1071) [`6c2c2630`](https://github.com/xataio/client-ts/commit/6c2c26308d4cbd25e7a9677c7d25c836396d4965) Thanks [@SferaDev](https://github.com/SferaDev)! - Add request timeout
84
+
85
+ ## 0.24.3
86
+
87
+ ### Patch Changes
88
+
89
+ - [#1033](https://github.com/xataio/client-ts/pull/1033) [`f01d1580`](https://github.com/xataio/client-ts/commit/f01d1580fc450cbf06eb8af85d68cf052fbe83a1) Thanks [@xata-bot](https://github.com/xata-bot)! - [OpenAPI] Spec updates for column selection
90
+
91
+ - [#1044](https://github.com/xataio/client-ts/pull/1044) [`52290feb`](https://github.com/xataio/client-ts/commit/52290feb5bba57384cdc14e7722fb5d9883dc581) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow undefined with createOrUpdate/createOrReplace
92
+
93
+ ## 0.24.2
94
+
95
+ ### Patch Changes
96
+
97
+ - [#1038](https://github.com/xataio/client-ts/pull/1038) [`51561b52`](https://github.com/xataio/client-ts/commit/51561b52b56ad5ed9101d8faf12929891419cb2c) Thanks [@SferaDev](https://github.com/SferaDev)! - Show internal columns in filters
98
+
99
+ ## 0.24.1
100
+
101
+ ### Patch Changes
102
+
103
+ - [#1030](https://github.com/xataio/client-ts/pull/1030) [`eaa774f5`](https://github.com/xataio/client-ts/commit/eaa774f542185ef92448155bcdff331686c4da9f) Thanks [@SferaDev](https://github.com/SferaDev)! - Make `xata` property enumerable
104
+
105
+ ## 0.24.0
106
+
107
+ ### Minor Changes
108
+
109
+ - [#1009](https://github.com/xataio/client-ts/pull/1009) [`45aa2207`](https://github.com/xataio/client-ts/commit/45aa220728e98dd716a55a9a307474732a9b2bc1) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `createdAt` and `updatedAt` properties
110
+
111
+ ### Patch Changes
112
+
113
+ - [#1008](https://github.com/xataio/client-ts/pull/1008) [`f28080f0`](https://github.com/xataio/client-ts/commit/f28080f034f02704fe00d64b8f42e1127bde30c7) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `failIfMissing` to delete transactions
114
+
115
+ - [#994](https://github.com/xataio/client-ts/pull/994) [`ac9c0604`](https://github.com/xataio/client-ts/commit/ac9c06042bb85105d9a38624676ce6ea5a27d488) Thanks [@xata-bot](https://github.com/xata-bot)! - Update internal endpoints
116
+
117
+ - [#1015](https://github.com/xataio/client-ts/pull/1015) [`c163b365`](https://github.com/xataio/client-ts/commit/c163b3658f23fb2eaad6243ebebc92624754099a) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `factor` to date boosters
118
+
119
+ ## 0.23.5
120
+
121
+ ### Patch Changes
122
+
123
+ - [#970](https://github.com/xataio/client-ts/pull/970) [`20cc8c43`](https://github.com/xataio/client-ts/commit/20cc8c43e1659bf112ae2642948c84bfcf46a6ba) Thanks [@xata-bot](https://github.com/xata-bot)! - Add delete file endpoint
124
+
125
+ - [#976](https://github.com/xataio/client-ts/pull/976) [`5099cbbd`](https://github.com/xataio/client-ts/commit/5099cbbd3065a60dcee2f1699afa1ee8ed5edb1c) Thanks [@SferaDev](https://github.com/SferaDev)! - Re-export JSONData helper type
126
+
127
+ - [#972](https://github.com/xataio/client-ts/pull/972) [`89375e76`](https://github.com/xataio/client-ts/commit/89375e76b790fed7e6a26bf3ac4ea9eaed1aecae) Thanks [@SferaDev](https://github.com/SferaDev)! - Add types to exports
128
+
129
+ - [#979](https://github.com/xataio/client-ts/pull/979) [`5eaee932`](https://github.com/xataio/client-ts/commit/5eaee932b828907ae352d7c0d0584e860845434b) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `size` to pagination meta
130
+
131
+ - [#974](https://github.com/xataio/client-ts/pull/974) [`109b8790`](https://github.com/xataio/client-ts/commit/109b8790849532d9c442e7c03c67792aeafebd88) Thanks [@xata-bot](https://github.com/xata-bot)! - Make checksum mandatory
132
+
133
+ ## 0.23.4
134
+
135
+ ### Patch Changes
136
+
137
+ - [#951](https://github.com/xataio/client-ts/pull/951) [`470cc71f`](https://github.com/xataio/client-ts/commit/470cc71f7c5c8b9fd50f789e157d2b2eecd0b3e8) Thanks [@SferaDev](https://github.com/SferaDev)! - Add random sorting
138
+
139
+ ## 0.23.3
140
+
141
+ ### Patch Changes
142
+
143
+ - [#947](https://github.com/xataio/client-ts/pull/947) [`344b0d68`](https://github.com/xataio/client-ts/commit/344b0d687962d569872d1e90d59818d28df7579c) Thanks [@SferaDev](https://github.com/SferaDev)! - Add numeric operators
144
+
145
+ ## 0.23.2
146
+
147
+ ### Patch Changes
148
+
149
+ - [#939](https://github.com/xataio/client-ts/pull/939) [`c477c177`](https://github.com/xataio/client-ts/commit/c477c17795c01cbf945be413217944a5a38655a5) Thanks [@SferaDev](https://github.com/SferaDev)! - Add deploy preview branch env variable loading
150
+
151
+ - [#945](https://github.com/xataio/client-ts/pull/945) [`ecdc6553`](https://github.com/xataio/client-ts/commit/ecdc6553d4628289e88953ab6296b80f60e8f757) Thanks [@xata-bot](https://github.com/xata-bot)! - Add new types
152
+
153
+ ## 0.23.1
154
+
155
+ ### Patch Changes
156
+
157
+ - [#941](https://github.com/xataio/client-ts/pull/941) [`3026d708`](https://github.com/xataio/client-ts/commit/3026d70847830fd0f2024413d823380ff323806c) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose records in ask SSE
158
+
159
+ ## 0.23.0
160
+
161
+ ### Minor Changes
162
+
163
+ - [#867](https://github.com/xataio/client-ts/pull/867) [`5838113f`](https://github.com/xataio/client-ts/commit/5838113fca042163b44d7cc7cc1686d5ef89b302) Thanks [@SferaDev](https://github.com/SferaDev)! - [Workflow] Remove fallback branch
164
+
165
+ ## 0.22.4
166
+
167
+ ### Patch Changes
168
+
169
+ - [#927](https://github.com/xataio/client-ts/pull/927) [`22e7dd29`](https://github.com/xataio/client-ts/commit/22e7dd29f7a51dccc087d5fd7fff32084c7733af) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose `ask` endpoint in the SDK
170
+
171
+ - [#921](https://github.com/xataio/client-ts/pull/921) [`07fc879d`](https://github.com/xataio/client-ts/commit/07fc879d3f778536e39588e66d7a18b5a9d52ebe) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove git branch resolution
172
+
173
+ - [#925](https://github.com/xataio/client-ts/pull/925) [`58a1c24e`](https://github.com/xataio/client-ts/commit/58a1c24e5d30025dce243eecce44f09d4f65ed66) Thanks [@xata-bot](https://github.com/xata-bot)! - Add new methods to API client
174
+
175
+ - [#932](https://github.com/xataio/client-ts/pull/932) [`c2c6e244`](https://github.com/xataio/client-ts/commit/c2c6e24459b1acc07f0414066258071fbcf7dde9) Thanks [@xata-bot](https://github.com/xata-bot)! - Add new experimental copy branch endpoint
176
+
177
+ ## 0.22.3
178
+
179
+ ### Patch Changes
180
+
181
+ - [#917](https://github.com/xataio/client-ts/pull/917) [`4210b8c3`](https://github.com/xataio/client-ts/commit/4210b8c3c4169ba781a56deed7ba09c99788db1f) Thanks [@xata-bot](https://github.com/xata-bot)! - [OpenAPI] Spec updates to add better types to Record input
182
+
183
+ ## 0.22.2
184
+
185
+ ### Patch Changes
186
+
187
+ - [#898](https://github.com/xataio/client-ts/pull/898) [`72e13bf9`](https://github.com/xataio/client-ts/commit/72e13bf99d0ebefef91c984a995a28b0e8ca2a8f) Thanks [@SferaDev](https://github.com/SferaDev)! - Add methods for vector type
188
+
189
+ ## 0.22.1
190
+
191
+ ### Patch Changes
192
+
193
+ - [#885](https://github.com/xataio/client-ts/pull/885) [`4cafde72`](https://github.com/xataio/client-ts/commit/4cafde728e4e9e5e83812d475d9980397ae78362) Thanks [@SferaDev](https://github.com/SferaDev)! - Update body of compareBranchSchemas
194
+
195
+ - [#890](https://github.com/xataio/client-ts/pull/890) [`639710a5`](https://github.com/xataio/client-ts/commit/639710a52132f260bf3a26560a21ae2193abb71d) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose consistency settings in summarize
196
+
197
+ ## 0.22.0
198
+
199
+ ### Minor Changes
200
+
201
+ - [#852](https://github.com/xataio/client-ts/pull/852) [`b2a4def4`](https://github.com/xataio/client-ts/commit/b2a4def4baf3eb18cd323895635e0bccb7f876f4) Thanks [@SferaDev](https://github.com/SferaDev)! - [BREAKING CHANGE] Reduce column selection depth
202
+
203
+ ### Patch Changes
12
204
 
13
205
  - [#835](https://github.com/xataio/client-ts/pull/835) [`379e6144`](https://github.com/xataio/client-ts/commit/379e61446b21e7cbadd7fc59267736c6845ec566) Thanks [@SferaDev](https://github.com/SferaDev)! - Add helper methods `toSerializable` and `toString`
14
206
 
package/README.md CHANGED
@@ -4,277 +4,4 @@ The Xata SDK supports typescript definitions for your Xata database schema. It a
4
4
 
5
5
  It has zero dependencies and runs in Node.js, V8, Deno and Bun.
6
6
 
7
- ## Installation
8
-
9
- See our [docs](https://xata.io/docs/sdk/typescript#installation) to get started using the Xata SDK.
10
-
11
-
12
- ## Table of Contents
13
-
14
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
15
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
16
-
17
- - [Installation](#installation)
18
- - [Usage](#usage)
19
- - [Schema-generated Client](#schema-generated-client)
20
- - [Schema-less Client](#schema-less-client)
21
- - [API Design](#api-design)
22
- - [Creating Records](#creating-records)
23
- - [Query a Single Record by its ID](#query-a-single-record-by-its-id)
24
- - [Querying Multiple Records](#querying-multiple-records)
25
- - [Updating Records](#updating-records)
26
- - [Deleting Records](#deleting-records)
27
- - [API Client](#api-client)
28
- - [Deno support](#deno-support)
29
-
30
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
31
-
32
- ## Manual Installation
33
-
34
- ```bash
35
- npm install @xata.io/client
36
- ```
37
-
38
- ## Usage
39
-
40
- There are three ways to use the SDK:
41
-
42
- - **Schema-generated Client**: SDK to create/read/update/delete records in a given database following a schema file (with type-safety).
43
- - **Schema-less Client**: SDK to create/read/update/delete records in any database without schema validation (with partial type-safety).
44
- - **API Client**: SDK to interact with the whole Xata API and all its endpoints.
45
-
46
- ### Schema-generated Client
47
-
48
- To use the schema-generated client, you need to run the code generator utility that comes with [our CLI](https://docs.xata.io/cli/getting-started).
49
-
50
- To run it (and assuming you have configured the project with `xata init`):
51
-
52
- ```bash
53
- xata codegen
54
- ```
55
-
56
- In a TypeScript file, start using the generated code like this:
57
-
58
- ```ts
59
- import { XataClient } from './xata'; // or wherever you chose to generate the client
60
-
61
- const xata = new XataClient();
62
- ```
63
-
64
- The import above will differ if you chose to generate the code in a different location.
65
-
66
- The `XataClient` constructor accepts an object with configuration options, like the `fetch` parameter, which is required only if your runtime doesn't provide a global `fetch` function. There's also a `databaseURL` argument that by default will contain a URL pointing to your database (e.g. `https://myworkspace-123abc.xata.sh/db/databasename`). It can be specified in the constructor to overwrite that value if for whatever reason you need to connect to a different workspace or database.
67
-
68
- The code generator will create two TypeScript types for each schema entity. The base one will be an `Identifiable` entity with the internal properties your entity has and the `Record` one will extend it with a set of operations (update, delete, etc...) and some schema metadata (xata version).
69
-
70
- ```ts
71
- interface User extends Identifiable {
72
- email?: string | null;
73
- }
74
-
75
- type UserRecord = User & XataRecord;
76
-
77
- async function initializeDatabase(admin: User): Promise<UserRecord> {
78
- return xata.db.users.create(admin);
79
- }
80
-
81
- const admin = await initializeDatabase({ email: 'admin@example.com' });
82
- await admin.update({ email: 'admin@foo.bar' });
83
- await admin.delete();
84
- ```
85
-
86
- You will learn more about the available operations below, under the [`API Design`](#api-design) section.
87
-
88
- ### Schema-less Client
89
-
90
- If you don't have a schema file, or you are building a generic way to interact with Xata, you can use the `BaseClient` class without schema validation.
91
-
92
- ```ts
93
- import { BaseClient } from '@xata.io/client';
94
-
95
- const xata = new BaseClient({
96
- branch: 'branchname',
97
- apiKey: 'xau_1234abcdef',
98
- fetch: fetchImplementation // Required if your runtime doesn't provide a global `fetch` function.
99
- });
100
- ```
101
-
102
- It works the same way as the code-generated `XataClient` but doesn't provide type-safety for your model.
103
-
104
- You can read more on the methods available below, in the next section.
105
-
106
- ### API Design
107
-
108
- The Xata SDK to create/read/update/delete records follows the [repository pattern](https://lyz-code.github.io/blue-book/architecture/repository_pattern/). Each table will have a repository object available at `xata.db.[table-name]`.
109
-
110
- 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.
111
-
112
- #### Creating Records
113
-
114
- Invoke the `create()` method in the repository. Example:
115
-
116
- ```ts
117
- const user = await xata.db.users.create({
118
- fullName: 'John Smith'
119
- });
120
- ```
121
-
122
- If you want to create a record with a specific ID, you can provide the id as parameter to the `create()` method.
123
-
124
- ```ts
125
- const user = await xata.db.users.create('user_admin', {
126
- fullName: 'John Smith'
127
- });
128
- ```
129
-
130
- And if you want to create or update a record with a specific ID, you can invoke `createOrUpdate()` with an id parameter.
131
-
132
- ```ts
133
- const user = await xata.db.users.createOrUpdate('user_admin', {
134
- fullName: 'John Smith'
135
- });
136
- ```
137
-
138
- #### Query a Single Record by its ID
139
-
140
- ```ts
141
- // `user` will be null if the record cannot be found
142
- const user = await xata.db.users.read('rec_1234abcdef');
143
- ```
144
-
145
- #### Querying Multiple Records
146
-
147
- ```ts
148
- // Query records selecting all fields.
149
- const page = await xata.db.users.select().getPaginated();
150
- const user = await xata.db.users.select().getFirst();
151
-
152
- // You can also use `xata.db.users` directly, since it's an immutable Query too!
153
- const page = await xata.db.users.getPaginated();
154
- const user = await xata.db.users.getFirst();
155
-
156
- // Query records selecting just one or more fields
157
- const page = await xata.db.users.select('email', 'profile').getPaginated();
158
-
159
- // Apply constraints
160
- const page = await xata.db.users.filter('email', 'foo@example.com').getPaginated();
161
-
162
- // Sorting
163
- const page = await xata.db.users.sort('full_name', 'asc').getPaginated();
164
- ```
165
-
166
- 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()`.
167
-
168
- To learn the differences between these methods, see the [reference](https://docs.xata.io/sdk/reference#query).
169
-
170
- ```ts
171
- // Operators that combine multiple conditions can be deconstructed
172
- const { filter, any, all, not, sort } = xata.db.users;
173
- const query = filter('email', 'foo@example.com');
174
-
175
- // Single-column operators are imported directly from the package
176
- import { gt, includes, startsWith } from '@xata.io/client';
177
- filter('email', startsWith('username')).not(filter('created_at', gt(somePastDate)));
178
-
179
- // Queries are immutable objects. This is useful to derive queries from other queries
180
- const admins = filter('admin', true);
181
- const spaniardsAdmins = admins.filter('country', 'Spain');
182
- await admins.getAll(); // still returns all admins
183
-
184
- // Finally fetch the results of the query
185
- const users = await query.getAll();
186
- const firstUser = await query.getFirst();
187
- ```
188
-
189
- The `getPaginated()` method will return a `Page` object. It's a wrapper that internally uses cursor based pagination.
190
-
191
- ```ts
192
- page.records; // Array of records
193
- page.hasNextPage(); // Boolean
194
-
195
- const nextPage = await page.nextPage(); // Page object
196
- const previousPage = await page.previousPage(); // Page object
197
- const startPage = await page.startPage(); // Page object
198
- const endPage = await page.endPage(); // Page object
199
- ```
200
-
201
- If you want to use an iterator, both the Repository and the Query classes implement an `AsyncIterable`. Alternatively you can use `getIterator()` and customize the batch size of the iterator:
202
-
203
- ```ts
204
- for await (const record of xata.db.users) {
205
- console.log(record);
206
- }
207
-
208
- for await (const record of xata.db.users.filter('team.id', teamId)) {
209
- console.log(record);
210
- }
211
-
212
- for await (const records of xata.db.users.getIterator({ batchSize: 100 })) {
213
- console.log(records);
214
- }
215
- ```
216
-
217
- #### Updating Records
218
-
219
- Updating a record leaves the existing object unchanged, but returns a new object with the updated values.
220
-
221
- ```ts
222
- // Using an existing object
223
- const updatedUser = await user.update({
224
- fullName: 'John Smith Jr.'
225
- });
226
-
227
- // Using a record id
228
- const updatedUser = await xata.db.users.update('rec_1234abcdef', {
229
- fullName: 'John Smith Jr.'
230
- });
231
- ```
232
-
233
- #### Deleting Records
234
-
235
- ```ts
236
- // Using an existing object
237
- await user.delete();
238
-
239
- // Using a record id
240
- await xata.db.users.delete('rec_1234abcdef');
241
- ```
242
-
243
- ### API Client
244
-
245
- One of the main features of the SDK is the ability to interact with the whole Xata API and perform administrative operations such as creating/reading/updating/deleting [workspaces](https://docs.xata.io/concepts/workspaces), databases, tables, branches...
246
-
247
- To communicate with the SDK we provide a constructor called `XataApiClient` that accepts an API token and an optional fetch implementation method.
248
-
249
- ```ts
250
- const api = new XataApiClient({ apiKey: process.env.XATA_API_KEY });
251
- ```
252
-
253
- 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`...).
254
-
255
- ```ts
256
- const { id: workspace } = await api.workspaces.createWorkspace({ name: 'example' });
257
- const { databaseName } = await api.database.createDatabase(workspace, 'database', { region: 'eu-west-1' });
258
-
259
- await api.branches.createBranch(workspace, databaseName, 'branch');
260
- await api.tables.createTable(workspace, databaseName, 'branch', 'table');
261
- await api.tables.setTableSchema(workspace, databaseName, 'branch', 'table', {
262
- columns: [{ name: 'email', type: 'string' }]
263
- });
264
-
265
- const { id: recordId } = await api.records.insertRecord(workspace, databaseName, 'branch', 'table', {
266
- email: 'example@foo.bar'
267
- });
268
-
269
- const record = await api.records.getRecord(workspace, databaseName, 'branch', 'table', recordId);
270
-
271
- await api.workspaces.deleteWorkspace(workspace);
272
- ```
273
-
274
- ## Deno support
275
-
276
- We publish the client on [deno.land](https://deno.land/x/xata). You can use it by changing the import in the auto-generated `xata.ts` file:
277
-
278
- ```ts
279
- import { buildClient, BaseClientOptions, XataRecord } from 'https://deno.land/x/xata/mod.ts';
280
- ```
7
+ You can find the SDK documentation [here](https://xata.io/docs/typescript-client/overview).