drizzle-orm-libsql-sync
v0.0.0
Published
A synchronous Drizzle ORM driver for libsql, backed by the libsql Database (prepare/exec) and drizzle v1 modern relations.
Maintainers
Readme
drizzle-orm-libsql-sync
A synchronous Drizzle ORM driver for
libsql, backed directly by the
libsql Database (prepare/exec) and targeting Drizzle v1's modern relations.
Why this exists
Drizzle ships two relevant SQLite drivers, but neither fits a sync + libsql + modern-relations use case:
drizzle-orm/libsqlis async (await db.execute(...)). Great for Turso over the network, but heavy for serial Node/Bun build scripts, test seeding, and benchmarks where every row insert would otherwise beawaited.drizzle-orm/better-sqlite3is sync, but it does a top-levelimport Client from "better-sqlite3"(forcing that dependency) and historically targeted Drizzle's legacy relational system.
This package gives you the missing combination: a real
BaseSQLiteDatabase<"sync", …> whose select()/insert()/... return rows
directly, bound to a libsql Database. libsql is a SQLite superset (more ALTER
statements, encryption-at-rest, extensions), so it's a strong local engine for
build/CLI/test code.
Note: This is for synchronous, local work (Node/Bun build scripts, fixtures, benchmarks). For your app talking to Turso over the network, keep using the official async
drizzle-orm/libsql.
Install
npm i drizzle-orm-libsql-sync drizzle-orm libsqldrizzle-orm and libsql are peer dependencies.
Usage
import Database from "libsql";
import { drizzle } from "drizzle-orm-libsql-sync";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
const users = sqliteTable("users", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
});
// Pass a path…
const db = drizzle("file:local.db", { schema: { users } });
// …or an existing libsql client…
const client = new Database(":memory:");
const db2 = drizzle(client, { schema: { users } });
// …or the config-object form:
const db3 = drizzle({ client, schema: { users } });
// Synchronous — no await:
db.insert(users).values({ name: "ada" }).run();
const rows = db.select().from(users).all();Migrations
import { migrate } from "drizzle-orm-libsql-sync/migrator";
migrate(db, { migrationsFolder: "./drizzle" });Transactions
db.transaction((tx) => {
tx.insert(users).values({ name: "grace" }).run();
// throw to roll back; nested transactions use SAVEPOINTs
});License
MIT
