Drizzle + Turso
Configure Drizzle to work with Turso
Prerequisites
Before you start, make sure you:
Install Drizzle and the libSQL SDK
Finish by updating package.json
to include three new scripts
:
Retrieve database credentials
Get the database URL:
Get the database authentication token:
Assign credentials to the environment variables inside .env
.
Create a Drizzle schema
Configure Drizzle Kit
Create the file drizzle.config.ts
in the root of your project with the following:
We’re using dotenv
above, but if you’re using something like Next.js, Remix, Astro, or Vite, you can use their built-in environment variables manager to source these values.
Connect Drizzle with libSQL
Database migrations
Drizzle can generate and apply database migrations with drizzle-kit
.
Whenever you make changes to the schema, run db:generate
:
Now apply these changes to the database with db:migrate
:
Query
Connect Drizzle Studio
Vector Embeddings
You can extend Drizzle to support Turso’s native vector — learn more.
Define custom vector type
Inside db/schema.ts
, add the following:
Create a table with a vector column
Now where you define the schema, invoke float32Array
to create a column that stores vectors:
Create a vector index
You will need to use raw SQL to create the index:
Insert vector data
Query vector data
Calculate vector distance:
Perform efficient nearest neighbor search:
Remember to create appropriate indexes for efficient vector operations and adjust vector dimensions as needed for your use case.