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);