SvelteKit banner

Prerequisites

Before you start, make sure you:

1

Install the libSQL SDK

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

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.

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
3

Configure LibSQL Client.

import { TURSO_DATABASE_URL, TURSO_AUTH_TOKEN } from "$env/static/private";
import { createClient } from "@libsql/client";

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

Execute SQL

import { turso } from "$lib/turso.server";

export async function load() {
  const { rows } = await turso.execute("SELECT * FROM table_name");

  return { rows };
}

Examples