We're excited to introduce the Turso Serverless JavaScript Driver - a new way to connect to your Turso databases from serverless and edge compute environments using only the fetch
API.
This experimental driver opens up Turso to platforms where traditional database drivers can't run, including Cloudflare Workers, Vercel Edge Functions, and other edge runtimes that don't support TCP connections.
Until now, connecting to databases from edge environments meant compromising on performance or functionality. With this driver, you get:
fetch()
— works anywhere JavaScript runsInstall the driver:
npm install @tursodatabase/serverless
Connect and query your database:
import { connect } from '@tursodatabase/serverless';
const conn = connect({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
// Prepare a statement
const stmt = conn.prepare('SELECT * FROM users WHERE id = ?');
// Get first row
const row = await stmt.get([123]);
console.log(row);
// Get all rows
const rows = await stmt.all([123]);
console.log(rows);
// Stream through rows (memory efficient for large datasets)
for await (const row of stmt.iterate([123])) {
console.log(row);
}
Execute multiple statements efficiently:
await conn.batch([
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, email TEXT)',
"INSERT INTO users (email) VALUES ('user@example.com')",
"INSERT INTO users (email) VALUES ('admin@example.com')",
]);
If you're already using the LibSQL client, switching is seamless with our compatibility layer:
import { createClient } from '@tursodatabase/serverless/compat';
const client = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
// Works just like the standard LibSQL client
const result = await client.execute('SELECT * FROM users WHERE id = ?', [123]);
console.log(result.rows);
The Turso Serverless JavaScript Driver shares the same API as @tursodatabase/turso
, making it incredibly easy to switch your application between remote and local environments. All you need to do is change the package import.
When you're developing locally or in environments that support file system access, use @tursodatabase/turso
for an embedded database with maximum performance. When deploying to serverless or edge environments like Cloudflare Workers, Vercel Edge Functions, or Deno Deploy, simply switch to @tursodatabase/serverless
and your code continues to work exactly the same way.
This unified API approach means you can develop locally with an embedded database for fastest iteration, then deploy anywhere without changing your database code. You maintain complete consistency across your entire application stack while switching environments seamlessly as your needs evolve.
Whether you're building on Cloudflare Workers, Vercel Edge Functions, or Deno Deploy, you can now connect to your Turso database without proxies or workarounds.
This driver is currently experimental and subject to change as we refine the API based on your feedback. We're committed to making this the best way to connect to SQLite databases from edge environments, and your input is crucial to that process.
The Turso Serverless JavaScript Driver is available now:
npm install @tursodatabase/serverless
We can't wait to see what you build with Turso at the edge. Try it out and let us know what you think on Discord.
Happy building!