MyGit

3.14.0

prisma/prisma

版本发布时间: 2022-05-10 22:41:55

prisma/prisma最新发布版本:5.19.1(2024-09-02 22:57:37)

🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟

Major improvements

CockroachDB connector is now Generally Available!

We are proud to announce the CockroachDB connector is now stable and Generally Available. The connector was built in joined efforts with the team at Cockroach Labs and comes with full Prisma Client and Prisma Migrate support.

If you're upgrading from Prisma version 3.9.0+ or the PostgreSQL connector, you can now run npx prisma db pull and review the changes to your schema. To learn more about CockroachDB-specific native types we support, refer to our docs.

To learn more about the connector and how it differs from PostgreSQL, head to our documentation.

PostgreSQL GIN, GiST, SP-GiST, and BRIN indexes support (Preview)

We introduced the extendedIndexes Preview feature in version 3.5.0, and we have been adding new configuration options for indexes. We've expanded index type support with the GIN, GiST, SP-GiST, and BRIN indexes in this release.

To make use of an index type, you can update your Prisma schema by providing the type argument to the @@index attribute:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["extendedIndexes"]
}

model Post {
  id      Int     @id
  title   String
  content String?
  tags    Json?

  @@index([tags], type: Gin)
}

The following SQL will be generated in your migration when you run prisma migrate dev:

CREATE TABLE "Post" (
    "id" INTEGER NOT NULL,
    "title" TEXT NOT NULL,
    "content" TEXT,
    "tags" JSONB,
    CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);

CREATE INDEX "Post_tags_idx" ON "Post" USING GIN ("tags");

To learn more about configuring index types in your schema, refer to our documentation.

Improved queryRaw API

In this release, we made improvements to the SQL raw API. Some improvements are breaking and will be available behind the new improvedQueryRaw Preview feature flag.

The improvedQueryRaw Preview feature solves most of the issues faced when working with the raw API. We would encourage you to turn on the Preview feature flag, try out the new API, and let us know how we can make it even better.

You can enable the Preview feature in your Prisma schema as follows:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["improvedQueryRaw"]
}

Here's a list of the improvements improvedQueryRaw comes with:

1. Raw scalar values are deserialized as their correct JavaScript types

Prisma Client queries such as findMany deserialize database scalar values to their corresponding JavaScript types. For example, a DateTime value is deserialized as a JavaScript Date, and a Bytes would be deserialized as a JavaScript Buffer.

Raw queries now implement the same behavior when the improvedQueryRaw Preview feature flag is enabled.

⚠️ This change is not yet available in the SQLite connector.

The types of values from the database will be used instead of the types in the Prisma schema. Here's an example query and response:

const res = await prisma.$queryRaw`SELECT bigint, bytes, decimal, date FROM "Table";`
console.log(res) 
// [{ bigint: BigInt("123"), bytes: Buffer.from([1, 2]), decimal: new Prisma.Decimal("12.34"), date: Date("<some_date>") }]

Here's a table that recaps the serialization type-mapping for raw results:

Database Type Javascript Type
Text String
Int32 Number
Float Number
Double Number
Int64 BigInt
Numeric Decimal
Bytes Buffer
Json Object
DateTime Date
Date Date
Time Date
Uuid String
Xml String

2. PostgreSQL type-casts

We've also fixed a lot of PostgreSQL type-casts that were broken by enabling the improvedQueryRaw Preview feature flag.

Here's an example of a query that used to fail:

await prisma.$queryRaw`SELECT ${1.5}::int as int`;
// Before: db error: ERROR: incorrect binary data format in bind parameter 1
// After: [{ int: 2 }]

You can now perform some more type-casts in your queries:

await prisma.$queryRaw`SELECT ${2020}::float4, (NOW() - ${"1 day"}::interval), ${"2022-01-01 00:00:00"}::timestamptz;`

A consequence of this fix is that some subtle implicit casts are now handled more strictly and would fail. Here's an example that used to work but won't work anymore under the improvedQueryRaw feature flag:

await prisma.$queryRaw`SELECT LENGTH(${42});`
// ERROR: function length(integer) does not exist
// HINT: No function matches the given name and argument types. You might need to add explicit type casts.

The LENGTH PostgreSQL function only accept text as input. Prisma used to coerce 42 to text silently, but won’t anymore. As suggested by the hint, cast 42 to text as follows:

await prisma.$queryRaw`SELECT LENGTH(${42}::text);`

3. Query parameters are correctly sent to the database

This improvement is available without the improvedQueryRaw Preview feature flag.

Before this release, query parameters of type BigInt, Bytes, and Decimal were incorrectly sent to the database leading to instances of unexpected inserts. Passing the types as query parameters now works:

await prisma.$executeRaw`INSERT INTO "Table" ("bigint", "bytes", "decimal") VALUES (${BigInt("123")}, ${Buffer.from([1, 2, 3])}, ${new Prisma.Decimal("12.23")});`

Fixes and improvements

Prisma Client

Prisma

Prisma Migrate

Language tools (e.g. VS Code)

Credits

Huge thanks to @ever0de, @flatplate, @njmaeff, @tnzk, @DePasqualeOrg for helping!

Prisma Day

Prisma Day is back this year, and it'll be on June 15 - 16 at the JamesJune Sommergarten in Berlin. Join us in-person or online for talks and workshops on modern application development and databases. Come and meet and chat with the team behind the Prisma ORM and Prisma Data Platform.

💼 We're hiring!

If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.

We're hiring for a number of roles: Technical Support Engineer, Back-end Engineer: Prisma Data Platform, and a Developer Advocate(Frontend/ Fullstack). You can find more jobs we're hiring for on our jobs page.

Feel free to read through the job descriptions and apply using the links provided.

📺 Join us for another "What's new in Prisma" livestream

Learn about the latest release and other news from the Prisma community by joining us for another "What's new in Prisma" livestream.

The stream takes place on YouTube on Thursday, May 12 at 5 pm Berlin | 8 am San Francisco.

相关地址:原始地址 下载(tar) 下载(zip)

查看:2022-05-10发行的版本