Skip to content

5.12.0

Compare
Choose a tag to compare
@grpatel grpatel released this 02 Apr 14:10
· 87 commits to main since this release
b8f741a

Today, we are excited to share the 5.12.0 stable release 🎉

🌟 Help us spread the word about Prisma by starring the repo or posting on X about the release.

Highlights

Cloudflare D1 (Preview)

This release brings Preview support for Cloudflare D1 with Prisma ORM 🥳

D1 is Cloudflare’s SQLite database that can be used when deploying applications with Cloudflare.

When using Prisma ORM with D1, you can continue to: model your database with Prisma schema language, specify sqlite as your database provider in your Prisma schema, and interact with your database using Prisma Client.

To use Prisma ORM and D1 on Cloudflare Workers or Cloudflare Pages, you need to set sqlite as your database provider and use the @prisma/adapter-d1 database adapter via the driverAdapters Preview feature, released back in version 5.4.0.

Here is an example of sending a query to your D1 database using Prisma Client in your Worker:

// src/index.ts file
import { PrismaClient } from '@prisma/client'
import { PrismaD1 } from '@prisma/adapter-d1'

// Add the D1Database to the Env interface
export interface Env {
// This must match the binding name defined in your wrangler.toml configuration
  DB: D1Database
}

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    // Make sure the database name matches the binding name in wrangler.toml and Env interface
    const adapter = new PrismaD1(env.DB)
    // Instantiate PrismaClient using the PrismaD1 driver adapter
    const prisma = new PrismaClient({ adapter })

    const users = await prisma.user.findMany()
    const result = JSON.stringify(users)
    return new Response(result)
  },
}

📚 Documentation: D1 Documentation

✍️ Blog post: Build Applications at the Edge with Prisma ORM & Cloudflare D1 (Preview)

📣 Share your feedback: D1 Driver Adapter

🚀 Example project: Deploy a Cloudflare Worker with D1

createMany() for SQLite

Bringing support for createMany() in SQLite has been a long-awaited feature

createMany() is a method on Prisma Client, released back in version 2.16.0, that lets you insert multiple records into your database at once. This can be really useful when seeding your database or inserting bulk data.

Here is an example of using createMany() to create new users:

const users = await prisma.user.createMany({
  data: [
    { name: 'Sonali', email: 'sonali@prisma.io' },
    { name: 'Alex', email: 'alex@prisma.io' },
    { name: 'Yewande', email: 'yewande@prisma.io' },
    { name: 'Angelina', email: 'angelina@prisma.io' },
  ],
})

Before this release, if you wanted to perform bulk inserts with SQLite, you would have most likely used $queryRawUnsafe to execute raw SQL queries. But now you don’t have to go through all that trouble 🙂

With SQLite, createMany() works exactly the same way from an API standpoint as it does with other databases except it does not support the skipDuplicates option. At the behavior level, SQLite will split createMany() entries into multiple INSERT queries when the model in your schema contains fields with attributes like @default(dbgenerated()) or @default(autoincrement()) and when the fields are not consistently provided with values across the entries.

📚Documentation: createMany() - Prisma Client API Reference

Fixes and Improvements

Prisma Client

Credits

Huge thanks to @yubrot, @skyzh, @anuraaga, @onichandame, @LucianBuzzo, @RobertCraigie, @arthurfiorette, @elithrar for helping!