Drizzle <> Turso Database Sync

This guide assumes familiarity with:

According to the official website, Turso is the small database to power your big dreams in the age of AI.

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i drizzle-orm@rc @tursodatabase/sync
npm i -D drizzle-kit@rc

Step 2 - Initialize the driver and make a query

import { drizzle } from 'drizzle-orm/tursodatabase-sync';

const db = drizzle({
	connection: {
    	path: 'local.db',                // path used as a prefix for local files created by sync-engine
    	url: 'https://<db>.turso.io',    // URL of the remote database: turso db show <db>
    	authToken: '...',                // auth token issued from the Turso Cloud: turso db tokens create <db>
    	clientName: 'turso-sync-example' // arbitrary client name
	}
});

const result = await db.all('select 1');

If you need to provide your existing drivers:

import { connect } from '@tursodatabase/sync';
import { drizzle } from 'drizzle-orm/tursodatabase-sync';

const client = await connect({
    path: 'local.db',                // path used as a prefix for local files created by sync-engine
    url: 'https://<db>.turso.io',    // URL of the remote database: turso db show <db>
    authToken: '...',                // auth token issued from the Turso Cloud: turso db tokens create <db>
    clientName: 'turso-sync-example' // arbitrary client name
});
const db = drizzle({ client });

const result = await db.all('select 1');

Whatโ€™s next?