This example shows how to use the Drizzle ORM with the Open Source libSQL server and the Turso managed offering.
cp .env.example .env
pnpm i
pnpm start
It will start a local server on port 3000.
curl --request POST \
--url http://localhost:3000/users \
--header 'Content-Type: application/json' \
--data '{
"name": "John Doe",
"email": "john@test.com"
}'
src/index.ts
- the main entry pointsrc/schema.ts
- defines the database schemamigrations
- contains the SQL migrations generated with Drizzle Kitsrc/env.ts
- loads, validates and exports the environment variablessrc/server.ts
- the server definitionsrc/utils.ts
- utility functions
pnpm generate
- generate a new migration based on schema changes
Migrations are run automatically when the server starts.
For Turso, JWT authentication tokens are needed. This assumes you have already
created a database with the turso db create
command.
Getting the database URL:
turso db show <database>
Getting auth token:
turso db tokens create <database> -e none
.env
:
DATABASE_URL=libsql://...
DATABASE_AUTH_TOKEN=ey...