Data - Turso

Guide to setting up and using Turso Cloud

Introduction

Turso is a cloud database platform built on libSQL, an open-source fork of SQLite.

It is designed for edge and serverless environments — each database is a lightweight SQLite file hosted on the cloud, accessible over HTTP from any runtime (Node.js, Deno, Bun, browsers, Cloudflare Workers, Netlify Edge Functions, etc.).

Key features:

  • SQLite-compatible — standard SQL, no new query language to learn
  • Serverless-first — connects over HTTP/WebSockets, no persistent connection needed
  • Global replication — replicate databases closer to users with embedded replicas
  • Free tier — generous limits for development and small projects

Cloud

Refer to the official Turso Cloud documentation for more information.

Quickstart

Quick Start

Install the Turso CLI using the following command:

Terminal window
curl -sSfL https://get.tur.so/install.sh | bash

The next command will open your browser to sign up:

Terminal window
turso auth signup

Now create your first database with the name my-db:

Terminal window
turso db create my-db

You can inspect your new database using the following command:

Terminal window
turso db show my-db

Congratulations, you created a database! Now connect to it with the shell command:

Terminal window
turso db shell my-db

Replace my-db with the name of your database if you named it differently.

Now create a table for users using SQL:

CREATE TABLE users (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT
);

Then insert a row into the users table:

INSERT INTO users (name) VALUES ('Iku');

Finally, query for all users:

SELECT * FROM users;

When you’re ready to move onto the next step, quit the shell:

.quit

SDK

@tursodatabase/serverless is the recommended package for any application that connects to a remote Turso Cloud database over the network.

It uses only fetch — zero native dependencies, works everywhere.

You will need an existing database to continue. If you don’t have one, create one.

Get the database URL:

Terminal window
turso db show --url <database-name>

Get the database authentication token:

Terminal window
turso db tokens create <database-name>

Assign credentials to environment variables inside .env:

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=

Install dependency:

Terminal window
deno add @tursodatabase/serverless

Connect to your database:

import { connect } from "@tursodatabase/serverless";
const conn = connect({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});

Execute a query using SQL

const stmt = await conn.prepare("SELECT * FROM users");
const rows = await stmt.all();

If you need to use placeholders for values, you can do that:

const stmt = await conn.prepare("SELECT * FROM users WHERE id = ?");
const row = await stmt.get([1]);