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 i drizzle-orm @libsql/client
npm i -D drizzle-kit
yarn add drizzle-orm @libsql/client
yarn add -D drizzle-kit
pnpm add drizzle-orm @libsql/client
pnpm add -D drizzle-kit
bun add drizzle-orm @libsql/client
bun add -D drizzle-kit
Step 2 - Initialize the driver
Drizzle has native support for all @libsql/client
driver variations:
@libsql/client
defaults to node
import, automatically changes to web
if target
or platofrm
is set for bundler, e.g. esbuild --platform=browser
@libsql/client/node
node
compatible module, supports :memory:
, file
, wss
, http
and turso
conneciton protocols@libsql/client/web
module for fullstack web frameworks like next
, nuxt
, astro
, etc. @libsql/client/http
module for http
and https
connection protocols @libsql/client/ws
module for ws
and wss
conneciton protocols @libsql/client/sqlite3
module for :memory:
and file
conneciton protocols @libsql/client-wasm
Separate 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
}});
import { drizzle } from 'drizzle-orm/libsql/node' ;
const db = drizzle ({ connection : {
url : process . env . DATABASE_URL ,
authToken : process . env . DATABASE_AUTH_TOKEN
}});
import { drizzle } from 'drizzle-orm/libsql/web' ;
const db = drizzle ({ connection : {
url : process . env . DATABASE_URL ,
authToken : process . env . DATABASE_AUTH_TOKEN
}});
import { drizzle } from 'drizzle-orm/libsql/http' ;
const db = drizzle ({ connection : {
url : process . env . DATABASE_URL ,
authToken : process . env . DATABASE_AUTH_TOKEN
}});
import { drizzle } from 'drizzle-orm/libsql/ws' ;
const db = drizzle ({ connection : {
url : process . env . DATABASE_URL ,
authToken : process . env . DATABASE_AUTH_TOKEN
}});
import { drizzle } from 'drizzle-orm/libsql/wasm' ;
const db = drizzle ({ connection : {
url : process . env . DATABASE_URL ,
authToken : process . env . DATABASE_AUTH_TOKEN
}});
If you need to provide your existing driver:
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 ()
import { drizzle } from 'drizzle-orm/libsql/web' ;
import { createClient } from '@libsql/client/web' ;
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?