Skip to main content
Multilingual TursoDB, MVCC & AI Agent database guides Read Engine Guide →
Turso Cloud SDKs Official SDKs TypeScript Guides

Astro + Turso

Set up Turso in your Astro project in minutes.

Astro banner

Prerequisites

To get the most out of this guide, you’ll need to:

1. Install the libSQL SDK

Begin by installing the @libsql/client dependency in your project:

npm install @libsql/client
pnpm install @libsql/client
yarn add @libsql/client
deno add npm:@libsql/client

2. Configure database credentials

Get the database URL:

turso db show --url <database-name>

Get the database authentication token:

turso db tokens create <database-name>

Assign credentials to the environment variables inside .env.

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=

3. Configure libSQL client

import { createClient } from "@libsql/client/web";

export const turso = createClient({
  url: import.meta.env.TURSO_DATABASE_URL!,
  authToken: import.meta.env.TURSO_AUTH_TOKEN,
});
NOTE

Astro will soon introduce a new ENV API. Take a look.

4. Execute SQL

---
import { turso } from './turso'

const { rows } = await turso.execute('SELECT * FROM table_name')
---

Examples

Synced from official Turso documentation ( tursodatabase/turso-docs · MIT License) Official Docs ↗
Search
Press Esc to close · Powered by Pagefind