This project demonstrates the use of Prisma with the Query Compiler and Driver Adapters preview features.
It connects to a Turso database using the @prisma/adapter-libsql
adapter.
- Node.js (>= 18.x)
- pnpm (>= 8.x)
- Turso database (you can sign up at Turso)
- Clone the repository:
git clone https://github.com/prisma/qa-query-compiler-turso.git
cd qa-query-compiler-turso
- Install dependencies:
pnpm install
- Generate Prisma Client:
pnpm prisma generate
- Set up environment variables:
Create a
.env
file in the root of the project with the following variables:
DATABASE_URL="your_turso_database_url"
DATABASE_AUTH_TOKEN="your_turso_auth_token"
Replace your_turso_database_url
and your_turso_auth_token
with your actual Turso database URL and authentication token.
- Schema: The Prisma schema is located at
prisma/schema.prisma
. - Preview Features: This project uses the
queryCompiler
anddriverAdapters
preview features.
// prisma/schema.prisma
generator client {
provider = "prisma-client"
output = "../.generated/prisma"
previewFeatures = ["queryCompiler", "driverAdapters"]
}
- Adapter: The project uses
@prisma/adapter-libsql
to connect to Turso. The adapter is configured insrc/adapter.ts
and integrated viaprisma.config.ts
for migrations andsrc/index.ts
for the client.
- Development: To run the application (e.g., to execute queries defined in
src/index.ts
):
pnpm dev
- To compile the TypeScript source code:
pnpm build
prisma/schema.prisma
: Defines the database schema and Prisma Client generator configuration.prisma.config.ts
: Configures Prisma for features like migrations when using driver adapters.src/index.ts
: The main entry point of the application, demonstrating Prisma Client usage.src/adapter.ts
: Contains the setup for the LibSQL (Turso) adapter.src/env.ts
: Defines the TypeScript types for environment variables..env
: Stores environment variables (DATABASE_URL, DATABASE_AUTH_TOKEN). Note: This file should be in.gitignore
and not committed to version control.package.json
: Lists project dependencies and scripts.