Skip to content

Commit c7451aa

Browse files
divyenduzOxyjun
andauthored
update xata docs (#24330)
* update xata docs * add documentation link * Apply suggestions from code review * Adding back the note component. * Typo fix --------- Co-authored-by: Jun Lee <[email protected]>
1 parent cca429b commit c7451aa

File tree

2 files changed

+10
-90
lines changed

2 files changed

+10
-90
lines changed

src/content/docs/workers/databases/third-party-integrations/xata.mdx

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,100 +5,19 @@ title: Xata
55

66
import { Render, TabItem, Tabs } from "~/components";
77

8-
[Xata](https://xata.io) is a serverless data platform powered by PostgreSQL. Xata uniquely combines multiple types of stores (relational databases, search engines, analytics engines) into a single service, accessible through a consistent REST API.
8+
[Xata](https://xata.io) is a PostgreSQL database platform designed to help developers operate and scale databases with enhanced productivity and performance. Xata provides features like instant copy-on-write database branches, zero-downtime schema changes, data anonymization, AI-powered performance monitoring, and BYOC.
9+
910

1011
:::note
1112

12-
You can connect to Xata using [Hyperdrive](/hyperdrive) (recommended), or using the Xata client, `@xata.io/client`. Both provide connection pooling and reduce the amount of round trips required to create a secure connection from Workers to your database.
13+
You can connect to Xata using [Hyperdrive](/hyperdrive), which provides connection pooling and reduces the amount of round trips required to create a secure connection from Workers to your database.
1314

1415
Hyperdrive can provide lower latencies because it performs the database connection setup and connection pooling across Cloudflare's network. Hyperdrive supports native database drivers, libraries, and ORMs, and is included in all [Workers plans](/hyperdrive/platform/pricing/). Learn more about Hyperdrive in [How Hyperdrive Works](/hyperdrive/configuration/how-hyperdrive-works/).
1516

1617
:::
1718

18-
<Tabs>
19-
<TabItem label="Hyperdrive (recommended)">
19+
Refer to the full [Xata documentation](https://xata.io/documentation).
2020

2121
To connect to Xata using [Hyperdrive](/hyperdrive), follow these steps:
2222

23-
<Render file="xata-partial" product="hyperdrive"/>
24-
</TabItem>
25-
<TabItem label="Xata client">
26-
27-
## Set up an integration with Xata
28-
29-
To set up an integration with Xata:
30-
31-
1. You need to have an existing Xata database to connect to or create a new database from your Xata workspace [Create a Database](https://app.xata.io/workspaces).
32-
33-
2. In your database, you have several options for creating a table: you can start from scratch, use a template filled with sample data, or import data from a CSV file. For this guide, choose **Start with sample data**. This option automatically populates your database with two sample tables: `Posts` and `Users`.
34-
35-
3. Configure the Xata database credentials in your Worker:
36-
37-
You need to add your Xata database credentials as secrets to your Worker. First, get your database details from your [Xata Dashboard](https://app.xata.io), then add them as secrets using Wrangler:
38-
39-
```sh
40-
# Add the Xata API key as a secret
41-
npx wrangler secret put XATA_API_KEY
42-
# When prompted, paste your Xata API key
43-
44-
# Add the Xata branch as a secret
45-
npx wrangler secret put XATA_BRANCH
46-
# When prompted, paste your Xata branch name (usually 'main')
47-
48-
# Add the Xata database URL as a secret
49-
npx wrangler secret put XATA_DATABASE_URL
50-
# When prompted, paste your Xata database URL
51-
```
52-
53-
4. Install the [Xata CLI](https://xata.io/docs/getting-started/installation) and authenticate the CLI by running the following commands:
54-
55-
```sh
56-
npm install -g @xata.io/cli
57-
58-
xata auth login
59-
```
60-
61-
5. Once you have the CLI set up, In your Worker, run the following code in the root directory of your project:
62-
63-
```sh
64-
xata init
65-
```
66-
67-
Accept the default settings during the configuration process. After completion, a `.env` and `.xatarc` file will be generated in your project folder.
68-
69-
6. To enable Cloudflare access the secret values generated when running in development mode, create a `.dev.vars` file in your project's root directory and add the following content, replacing placeholders with the specific values:
70-
71-
```txt
72-
XATA_API_KEY=<YOUR_API_KEY_HERE>
73-
XATA_BRANCH=<YOUR_BRANCH_HERE>
74-
XATA_DATABASE_URL=<YOUR_DATABASE_URL_HERE>
75-
```
76-
77-
7. The following example shows how to make a query to your Xata database in a Worker. The credentials needed to connect to Xata have been added as secrets to your Worker.
78-
79-
```ts
80-
export default {
81-
async fetch(request, env, ctx): Promise<Response> {
82-
const xata = new XataClient({
83-
apiKey: env.XATA_API_KEY,
84-
branch: env.XATA_BRANCH,
85-
databaseURL: env.XATA_DATABASE_URL,
86-
});
87-
88-
const records = await xata.db.Posts.select([
89-
"id",
90-
"title",
91-
"author.name",
92-
"author.email",
93-
"author.bio",
94-
]).getAll();
95-
96-
return Response.json(records);
97-
},
98-
} satisfies ExportedHandler<Env>;
99-
```
100-
101-
To learn more about Xata, refer to [Xata's official documentation](https://xata.io/docs).
102-
103-
</TabItem>
104-
</Tabs>
23+
<Render file="xata-partial" product="hyperdrive" />

src/content/partials/hyperdrive/xata-partial.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { Render } from "~/components";
66

77
## 1. Allow Hyperdrive access
88

9-
You can connect Hyperdrive to any existing Xata database with the default user and password provided by Xata.
9+
You can connect Hyperdrive to any existing Xata PostgreSQL database with the connection string provided by Xata.
1010

1111
### Xata dashboard
1212

1313
To retrieve your connection string from the Xata dashboard:
1414

15-
1. Go to the [**Xata dashboard**](https://app.xata.io/).
15+
1. Go to the [**Xata dashboard**](https://xata.io/).
1616
2. Select the database you want to connect to.
17-
3. Select **Settings**.
18-
4. Copy the connection string from the `PostgreSQL endpoint` section and add your API key.
17+
3. Copy the `PostgreSQL` connection string.
18+
19+
Refer to the full [Xata documentation](https://xata.io/documentation).
1920

2021
## 2. Create a database configuration
2122

0 commit comments

Comments
 (0)