Turso Database Getting Started Connect
Connect to Turso using JavaScript
Connect to Turso using JavaScript — Turso documentation.
Quickstart
1. Install
Add the Turso database package to your JavaScript project:
npm i @tursodatabase/database
2. Connect
Here’s how you can connect to a local SQLite database:
import { connect } from "@tursodatabase/database";
const db = await connect("sqlite.db");
3. Create table
Create a table for users:
const createTable = db.prepare(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL
)
`);
createTable.run();
4. Insert data
Insert some data into the users table:
const insertUser = db.prepare("INSERT INTO users (username) VALUES (?)");
insertUser.run("alice");
insertUser.run("bob");
5. Query data
Query all users from the table:
const stmt = db.prepare("SELECT * FROM users");
const users = stmt.all();
console.log(users);
Examples
Explore these JavaScript examples to learn more about using Turso Database:
- Node — Node.js, local file database (no sync)
- Wasm + Vite — Browser (WASM), local database in the browser
Synced from official Turso documentation (
tursodatabase/turso-docs
· MIT License)
Official Docs ↗