Become a Gold Sponsor

Drizzle <> Turso

This guide assumes familiarity with:

According to the official website, Turso is a libSQL powered edge SQLite database as a service.

Drizzle ORM natively supports libSQL driver, we embrace SQL dialects and dialect specific drivers and syntax and mirror most popular SQLite-like all, get, values and run query methods syntax.

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i drizzle-orm @libsql/client
npm i -D drizzle-kit

Step 2 - Initialize the driver

Drizzle has native support for all @libsql/client driver variations:

@libsql/clientdefaults to node import, automatically changes to web if target or platofrm is set for bundler, e.g. esbuild --platform=browser
@libsql/client/nodenode compatible module, supports :memory:, file, wss, http and turso conneciton protocols
@libsql/client/webmodule for fullstack web frameworks like next, nuxt, astro, etc.
@libsql/client/httpmodule for http and https connection protocols
@libsql/client/wsmodule for ws and wss conneciton protocols
@libsql/client/sqlite3module for :memory: and file conneciton protocols
@libsql/client-wasmSeparate experimental package for WASM

default
node
web
http
web sockets
wasm
import { drizzle } from 'drizzle-orm/libsql';

const db = drizzle({ connection: {
  url: process.env.DATABASE_URL, 
  authToken: process.env.DATABASE_AUTH_TOKEN 
}});

If you need to provide your existing driver:

default
web
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';

const client = createClient({ 
  url: process.env.DATABASE_URL,
  authToken: process.env.DATABASE_AUTH_TOKEN
});

const db = drizzle({ client });

const result = await db.select().from(users).all()

Step 3 - make a query

import { drizzle } from 'drizzle-orm/libsql';
import * as s from 'drizzle-orm/sqlite-core';

const db = drizzle({ connection: {
  url: process.env.DATABASE_URL, 
  authToken: process.env.DATABASE_AUTH_TOKEN 
}});

const users = s.sqliteTable("users", {
  id: s.integer(),
  name: s.text(),
})

const result = await db.select().from(users);

What’s next?