Turso SDK for SQLite
Use @tursodatabase/serverless in your application. Create the demo disk and a project API key using the quickstart.
Run a query
Section titled “Run a query”npm install @tursodatabase/serverless@1.4.1import { connect } from "@tursodatabase/serverless";
const db = connect({ url: "https://api.wabe.sh/v1/disks/demo/sqlite/mydb/hrana/", authToken: "YOUR_PROJECT_API_KEY",});db.defaultSafeIntegers(true);await db.exec("CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY, body TEXT)");await db.run("INSERT INTO notes(body) VALUES (?)", "Hello");console.log(await db.all("SELECT id, body FROM notes ORDER BY id"));await db.close();defaultSafeIntegers(true) returns signed 64-bit row integers as bigint. The driver can still round large insert IDs in metadata.
Use Drizzle
Section titled “Use Drizzle”Install the tested versions.
npm install @tursodatabase/serverless@1.4.1 drizzle-orm@0.45.4 @libsql/client@0.17.0Create the notes table with the preceding example. The type assertion bridges differences in the two clients’ row types.
import type { Client } from "@libsql/client";import { createClient } from "@tursodatabase/serverless/compat";import { drizzle } from "drizzle-orm/libsql";import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
const notes = sqliteTable("notes", { id: integer("id").primaryKey(), body: text("body") });const client = createClient({ url: "https://api.wabe.sh/v1/disks/demo/sqlite/mydb/hrana/", authToken: "YOUR_PROJECT_API_KEY",}) as unknown as Client;const db = drizzle({ client, schema: { notes } });console.log(await db.select().from(notes));client.close();Use positional bindings with the compatibility client. Use the native client for exact 64-bit row integers.
See the SQLite HTTP API and SQL commands.