Skip to content

eaststrong/typedsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypedSQL Example

This example shows how to use the TypedSQL feature of Prisma ORM in a TypeScript project. TypedSQL allows you to write fully type-safe SQL queries and then run them via Prisma Client.

Getting started

2. Create and seed the database

Run the following command to create your SQLite database file. This also creates the User and Post tables that are defined in prisma/schema.prisma:

bun run migrate-init

When bun run migrate is executed against a newly created database, seeding is also triggered. The seed file in prisma/seed.ts will be executed and your database will be populated with the sample data.

3. Generate Prisma Client with SQL

bun run generate

This command runs prisma generate --sql, which will generate the Prisma Client and also check any SQL files in the prisma/sql directory. After type-checking the SQL files, they are compiled into JavaScript and added to the Prisma Client.

Tip

This also works with the --watch flag! If you want to automatically generate and watch for changes, you can use npx prisma generate --sql --watch.

4. Run the example

bun run dev

This command will run index.ts, which will execute the SQL query defined in prisma/sql/conversionByVariant.sql and print the results to the console.

Project Structure

This example project is structured similarly to the starter example with a key difference:

Key areas to look at:

  1. Database schema: prisma/schema.prisma
  2. Example SQL query: prisma/sql/conversionByVariant.sql
  3. Query execution: src/index.ts
  4. Data seeding: prisma/seed.ts
  5. Build and run scripts: package.json

Next steps

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published