SvelteKit banner

Prerequisites

Before you start, make sure you:

1

Install the libSQL SDK

npm install @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.local.

VITE_TURSO_DATABASE_URL="..."
VITE_TURSO_AUTH_TOKEN="..."
3

Configure LibSQL Client.

src/turso.ts
import { createClient } from "@libsql/client/web";

export const turso = createClient({
  url: process.env.TURSO_DATABASE_URL!,
  authToken: process.env.TURSO_AUTH_TOKEN,
});
4

Execute SQL

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

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

Examples