Type to search…

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:

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

The next command will open your browser to sign up:

shell
turso auth signup

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

shell
turso db create my-db

You can inspect your new database using the following command:

shell
turso db show my-db

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

shell
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:

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

Then insert a row into the users table:

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

Finally, query for all users:

sql
SELECT * FROM users;

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

sql
.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:

shell
turso db show --url <database-name>

Get the database authentication token:

shell
turso db tokens create <database-name>

Assign credentials to environment variables inside .env:

env
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=

Install dependency:

shell
deno add @tursodatabase/serverless

Connect to your database:

js
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

js
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:

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