Skip to content
Compare
Choose a tag to compare

3.4.0

@nikolasburk nikolasburk released this
· 90 commits to main since this release
a7c5041
Compare
Choose a tag to compare

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

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

Major improvements & new features

Support for PostgreSQL 14

We are pleased to announce that Prisma version 3.4.0 provides support for PostgreSQL 14. For a full list of our supported databases and their versions, see our documentation.

MongoDB

Support for Order By Aggregate Group

In Prisma version 3.4.0, we add support on MongoDB databases for using orderBy with aggregate groups. This was previously available for relational databases.

For example, if the data about your application's users includes their city of residence, you can determine which cities have the largest user groups. The following query sorts each city group by the number of users in that group, and returns the results in descending order (largest group first):

const groupBy = await prisma.user.groupBy({
  by: ['city'],
  _count: {
    city: true,
  },
  orderBy: {
    _count: {
      city: 'desc',
    },
  },
})

For more information refer to our documentation about ordering by groups.

Initial support for MongoDB in prisma db push

The prisma db push command is used to sync your Prisma schema and your database schema in development.

Because MongoDB has a unique approach to database schema management, this initial release only syncs @unique, @@unique and @@index annotations in your schema.

Let's look at a quick example using this Prisma schema:

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

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

model BlogPost {
  id    String @id @default(dbgenerated()) @map("_id") @db.ObjectId
  title String @unique
}

After running prisma db push the CLI will display which changes were made:

Applying the following changes:

[+] Unique index `BlogPost_title_key` on ({"title":1})

Let's keep iterating on the schema. We apply the following changes:

  • remove the unique index from title
  • add a compound unique index on the combination of author and title
  • add an index to title
datasource db {
  provider = "mongodb"
  url = env("DATABASE_URL")
}

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

model BlogPost {
  id     String @id @map("_id") @db.ObjectId
  author String
  title  String

  @@unique([author, title], map: "titleAuthorShouldBeUniqueUnique")
  @@index([title])
}

and run prisma db push again, we see what changes were applied:

Applying the following changes:

[-] Unique index `BlogPost_title_key`
[+] Index `BlogPost_title_idx` on ({"title":1})
[+] Unique index `titleAuthorShouldBeUniqueUnique` on ({"author":1,"title":1})

And voilà, the index and unique definitions in our schema are reflected in the database.

There is a known limitation with empty collections: if you db push indexes or uniques on fields that do not have values in the collection (they are missing in all existing documents), and you use db pull after that, the indexes and uniques will not be pulled because the fields will not be in your schema.

Since this is a Preview feature, any feedback is very much appreciated. Please get in touch by opening a GitHub issue.

Introspection of embedded documents in MongoDB

For those interested in helping us getting introspection of embedded documents right, we packaged a first iteration into the CLI. More info in the Github issue.

Prisma Client Go

Data Proxy Support

Connection limit issues got you down? By using Prisma's Data Proxy, you can pool your connections to avoid overloading your database.

With this release, Prisma Client Go can now read and write to the Data Proxy. Let's say you have the following project setup on the Prisma Data Platform.

CleanShot 2021-11-01 at 18.33.28@2x.png

You can generate a "Data Proxy"-enabled Go Client with the following command:

PRISMA_CLIENT_ENGINE_TYPE='dataproxy' go run github.com/prisma/prisma-client-go generate

Then you can use the Go Client as you normally would:

amas, err := client.Ama.FindMany().Exec(ctx)
if err != nil {
	return err
}
for _, ama := range amas {
	fmt.Println(ama.Status, ":", ama.Question)
}

// ANSWERED : How did you build this AMA page?
// ANSWERED : What is zero-cost type safety?
// UNANSWERED : What developer tools do you like?

Please note that the Data Proxy is currently in Early Access and still under active development. We do not recommend using the Data Proxy for production loads. If you run into any issues while trying to use the Go Client with the Data Proxy, please leave us a note in this issue.

JSON Filtering Support

We've had JSON filtering support in the TypeScript Client since . In 3.4.0, we're bringing support to the Go Client. Let's take a look at an example.

Given the following Prisma schema:

generator client {
  provider        = "prisma-client-go"
  previewFeatures = ["filterJson"]
}

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

model Log {
  id      Int    @id @default(autoincrement())
  level   Level
  message String
  meta    Json
}

enum Level {
  INFO
  WARN
  ERROR
}

You can now write the following to query a specific service name inside inside the meta field:

logs, _ := client.Log.FindMany(
    db.Log.Meta.Path([]string{"service"}),
    db.Log.Meta.Equals(db.JSON("\"api\"")),
).Exec(ctx)

See some more examples of what you can do in our documentation. Note that the examples are written in Typescript, but the same concepts apply to Go as well!

Fixes and improvements

Prisma Client

Prisma Migrate

Language tools (e.g. VS Code)

The Prisma Serverless Data Conference is happening on November 18!

Make sure to claim your ticket for our free Prisma Serverless Data Conference about all things databases and serverless with fantastic speakers from companies like PlanetScale, MongoDB, Vercel, Netlify, Cloudflare and CockroachDB.

📺 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, November 04 at 5pm Berlin | 9am San Francisco.