For this example I'm using the dir structure
src/lib/db/
migrations/
20240612T063030-creating_your_table.ts
20240613T063030-another_migration.ts
index.ts
migrate.ts
Feel free to modify to your needs.
TURSO_DATABASE_URL=libsql://........turso.io
TURSO_AUTH_TOKEN=......
DATABASE_URL=libsql://YOUR_TOKEN_HERE.@HOST HERE
- Create required files listed bellow following the correct directory structure.
- migrate.ts
- index.ts
pnpm db:migrate:up // Perform all new migrations
pnpm db:migrate:down // Rollback to previous migration
pnpm db:migrate:create // Create a new blank migration file
pnpm db:generate:types // Generate the types you can use on your product
From here you should be able to perform queries using kysely.
const response = await db
.selectFrom('YOUR_TABLE')
.select(['id', 'OTHER_COLUMN'])
.where('id', '=', id)
.executeTakeFirst()
This a simple example of how I'm running my projects using sqlite integrated with turso.
If you have a nodejs/bun project using postgres, have a look on this boilerplate that I also use on my API projects.