Xata & Astro
Этот содержимое пока не доступно на вашем языке.
Xata is a Serverless Data Platform that combines the features of a relational database, a search engine, and an analytics engine by exposing a single consistent REST API.
Adding a database with Xata
- A Xata account with a created database. (You can use the sample database from the Web UI.)
- An Access Token (
- Your Database URL.
After you update and initialize the Xata CLI, you will have your API token in your
.env file and database URL defined.
By the end of the setup, you should have:
To have IntelliSense and type safety for your environment variables, edit or create the file
env.d.ts in your
Using the codegeneration from the Xata CLI and choosing the TypeScript option, generated an instance of the SDK for you, with types tailored to your database schema. Additionally,
@xata.io/client was added to your
Your Xata environment variables and database url were automatically pulled by the SDK instance, so there’s no more setup work needed.
Now, your project should have the following structure:
Create your queries
To query your posts, import and use
XataClient class in a
.astro file. The example below queries the first 50 posts from Xata’s Sample Blog Database.
It’s important to note the SDK needs to be regenerated everytime your schema changes. So, avoid making changes to the generated files the Xata CLI creates because once schema updates, your changes will be overwritten.