Skip to main content
Turso ships two JavaScript packages. Both expose the same core API, modelled after the better-sqlite3 promise API.
PackageUse case
@tursodatabase/databaseNative bindings — Node.js, Bun, Deno
@tursodatabase/serverlessTurso Cloud (remote) databases

Installation

# Native (default — prebuilt binary for your platform)
npm install @tursodatabase/database

# WebAssembly build
npm install @tursodatabase/database --cpu wasm32

Quick start

import { connect } from '@tursodatabase/database';

// Open a file-backed database (created if it does not exist)
const db = await connect('turso.db');

// Execute DDL directly
db.exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)');

// Prepare and run a statement
const stmt = db.prepare('INSERT INTO users (name) VALUES (?)');
await stmt.run('Alice');

// Query rows
const rows = await db.prepare('SELECT * FROM users').all();
console.log(rows); // [{ id: 1, name: 'Alice' }]

db.close();

Entry point: connect(path, options?)

The connect function is the main entry point. It opens — and optionally creates — a database file and returns a Database object.
import { connect } from '@tursodatabase/database';

const db = await connect(':memory:');      // in-memory database
const db = await connect('./app.db');      // file-backed database
path
string
required
Path to the SQLite database file. Pass ":memory:" to open an in-memory database. The file is created if it does not exist.
options
DatabaseOpts
Optional configuration object. See Database for the full list of fields.

What these classes provide

Database

Represents a single connection. Prepare statements, run ad-hoc SQL, and close the connection.

Statement

A compiled SQL statement. Bind parameters, execute, and iterate over result rows.

Build docs developers (and LLMs) love