Skip to content

Turso

Quoted from the Turso documentation,

It’s an easy database to setup, and SQLite can be used quite easily on local environments.

Here is how to setup and use Turso with KitForStartups:

Create a Turso database

Before creating a database, you’ll need to install Turso CLI on your machine. Steps to do so can be found here.

Next, you can create a logical database using the following commands:

Terminal window
# Create a group
# https://docs.turso.tech/concepts#placement-group
turso group create my-group-name
# Create a database in the newly created group
# https://docs.turso.tech/concepts#database
turso db create my-db-name --group my-group

Update environments variables

The next step is to update the environment variables in your .env file. You can find the values for these variables in the Turso console.

For Turso, we need TURSO_DB_URL and TURSO_AUTH_TOKEN.

The token can be generated using the following command:

Terminal window
turso db tokens create my-db-name

For the DB URL, on local environments, you can use turso dev to invoke a libSQL server locally. This will open a websocket server that can be accessed on ws://127.0.0.1:8080 (this will be the value for TURSO_DB_URL).

Terminal window
turso dev -f src/lib/drizzle/turso/data.sqlite

Push the database schema

Once you have your database setup, you can push the schema using the following command:

Terminal window
pnpm push:turso

This will directly push the schema to the database without creating any migrations files.

If you want / need to create migrations files, you can use the following command:

Terminal window
pnpm generate-migrations:turso
pnpm migrate:turso

Search and replace the database configuration

In order to switch, the current option is to search and replace occurences of drizzle/mysql and lucia/mysql with drizzle/turso and lucia/turso respectively.

If you are using VSCode, you can exclude the src/lib/drizzle and src/lib/lucia folders from the search.