March 31, 2021

What's new in Prisma? (Q1/21)

Learn about everything that has happened in the Prisma ecosystem and community from January to March 2021.

Overview

Releases & new features

Our engineers have been hard at work issuing new releases with many improvements and new features every two weeks. Here is an overview of the most exciting features that we have launched in the last three months.

You can stay up-to-date about all upcoming features on our roadmap.

Prisma Migrate is generally available 🚀

The biggest news in this quarter certainly was the launch of Prisma Migrate for General Availability. This means, you can now use Prisma Migrate without the --preview-feature option:

Before v2.19.0

npx prisma migrate <COMMAND> --preview-feature
# for example:
npx prisma migrate dev --preview-feature

Now

npx prisma migrate <COMMAND>
# for example:
npx prisma migrate dev

You can learn more about this in the release notes, the announcement article and the video demo by Daniel and Tom.

Use native database types in the Prisma schema

In this quarter, we made it possible to use a much broader range of native database types in the Prisma schema.

For example, you can now define VARCHAR types of a specific length or use other database-specific types like (in this case for PostgreSQL) MONEY, variations of date/time types like TIME, TIMETZ or TIMESTAMPTZ and a lot more.

Here's an example:

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement()) @db.Integer
email String @unique @db.VarChar(191)
birthday DateTime? @db.Timestamptz
wealth Decimal @db.Money
}

For a full overview of available types, check out the type mapping sections in the docs:

Seed your database with the Prisma CLI (Preview)

The new prisma db seed command enables you to automatically invoke a seed script to feed your database with some initial data.

The command expects a file called seed with the respective file extension inside your main prisma directory:

  • JavaScript: prisma/seed.js
  • TypeScript: prisma/seed.ts
  • Shell: prisma/seed.sh

Alternatively you can pass the --schema option to the CLI command in order to point to the location of the seed script or define a default schema location in your package.json which will be picked up every time you run the command.

// prisma/seed.ts
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// A `main` function so that we can use async/await
async function main() {
const newUser = await prisma.user.create({
data: {
email: 'sarah@prisma.io',
},
})
console.log(`New user created`, newUser.id)
}
main()
.catch(e => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})

New features for the Prisma Client API

We regularly add new features to the Prisma Client API to enable more powerful database queries that were previously only possible via plain SQL and the $queryRaw escape hatch .

Order by relations (Preview)

Since 2.16.0, you can order the results of findMany queries by properties of related models. For example, you can order a list of posts alphabetically by the names of their authors:

cons posts = await prisma.post.findMany({
orderBy: [
{
author: {
name: 'asc',
},
},
],
})

Additionaly, the 2.19.0 release makes it possible to order by the aggregates (e.g. count) of relations as well. Here's is an example that orders a list of users by the number of the posts they created:

const users = await prisma.user.findMany({
orderBy: {
posts: {
count: 'asc',
},
},
})
Count on relations (Preview)

This highly requested feature is now Preview since 2.20.0. You can now count the number of related records by passing _count to the select or include options and then specifying which relation counts should be included in the resulting objects via another select.

For example, counting the number of posts that an user has written:

const users = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})
Copy
Efficient bulk creates with createMany

The new createMany operation (introduced in 2.16.0) enables you to insert data a whole lot faster:

const result = await prisma.user.createMany({
data: [
{ email: 'alice@prisma.io' },
{ email: 'nilu@prisma.io' },
{ email: 'mahmoud@prisma.io' },
{ email: 'etel@prisma.io' },
],
})
console.log(`Created ${result.count} users!`)
Directly set foreign keys

Since 2.15.0, it is possible to dirctly set foreign keys instead of wiring up relations via the connect API:

// An example of the new API that directly sets the foreign key
const user = await prisma.profile.create({
data: {
bio: 'Hello World',
userId: 42,
},
})
// If you prefer, you can still use the previous API via `connect`
const user = await prisma.profile.create({
data: {
bio: 'Hello World',
user: {
connect: { id: 42 }, // sets userId of Profile record
},
},
})
Group by

Since 2.14.0, Prisma Client supports group by queries:

const locations = await client.agent.groupBy({
by: ['location'],
min: {
rate: true,
},
})
Copy

Additionally, you can further filter the result by using the having option:

const locations = await client.agent.groupBy({
by: ['location', 'rate'],
min: {
rate: true,
},
having: {
rate: {
gte: 20,
},
},
})
Copy

You can learn more about these queries in the docs.

Reducing overhead between Node.js and Rust with N-API (Preview)

N-API is a new technique for binding Prisma's Rust-based query engine directly to Prisma Client that was introduced in 2.20.0. This reduces the communication overhead between the Node.js and Rust layers when resolving Prisma Client's database queries.

Enabling the N-API will not affect your workflows in any way, the experience of using Prisma will remain exactly the same.

The N-API has different runtime characteristics than the current communication layer between Node.js and Rust. There may be some rough edges during the Preview period.

New features for Prisma Client Go

In case you're not aware, Prisma Client also is available for Golang in an Early Access version.

You can learn more about Prisma Client Go in the documentation. Also note that we are actively looking for feedback for Prisma Client Go!

You can help us accelerate the release process by creating issues and sharing your feedback in the #prisma-client-go channel on the Prisma Slack.

This quarter, Prisma Client Go saw some exciting updates as well:

Upserts

post, _ := client.Post.UpsertOne(
// query
Post.ID.Equals("upsert"),
).Create(
// set these fields if document doesn't exist already
Post.Title.Set("title"),
Post.Views.Set(0),
Post.ID.Set("upsert"),
).Update(
// update these fields if document already exists
Post.Title.Set("new-title"),
Post.Views.Increment(1),
).Exec(ctx)

Dynamic filters

func CreateUser(w http.ResponseWriter, r *http.Request) {
var params []db.UserSetParam
email := r.PostFormValue("email")
kind := r.PostFormValue("kind")
if kind == "customer" {
// Set the referrer for users of type customer only
params = append(params, db.User.Referer.Set(r.Header.Get("Referer"))
}
user, err := client.User.CreateOne(
db.User.Kind.Set(kind),
db.User.Email.Set(email),
params...,
).Exec(r.Context())
// ... Handle the response
}

Transactions

createUserA := client.User.CreateOne(
db.User.ID.Set("c"),
db.User.Email.Set("a"),
)
createUserB := client.User.CreateOne(
db.User.ID.Set("d"),
db.User.Email.Set("b"),
)
err := client.Prisma.Transaction(createUserA, createUserB).Exec(ctx)
if err != nil {
return err
}

New types: BigInt, Decimal and Bytes

var views db.BigInt = 1
bytes := []byte("abc")
dec := decimal.NewFromFloat(1.23456789)
created, err := client.User.CreateOne(
db.User.Picture.Set(bytes),
db.User.Balance.Set(dec),
db.User.Views.Set(views),
).Exec(ctx)

Tools & ecosystem

Blitz

We are excited for the Blitz community to see them launch an official beta version of their framework, including a new website and documentation:

Blitz is a batteries-included framework that's inspired by Ruby on Rails, is built on Next.js, and features a "Zero-API" data layer abstraction that eliminates the need for REST/GraphQL. It uses Prisma as its default ORM layer.

KeystoneJS

While it's already possible to use KeystoneJS with Prisma as the ORM, the upcoming version of KeystoneJS will use Prisma as its default database adapter.

KeystoneJS founder Jed Watson recently was a guest on the What's new in Prisma livestream where he gave a demo of KeystoneJS with Prisma.

Wasp

Backed by YCombinator, the twin brothers Martin and Matija Šošić are building Wasp, a DSL for building fullstack web applications. They recently launched Wasp on Hacker News.

To learn more about Wasp, be sure to check out Matija's talk at our recent Prisma Meetup:

Amplication

Amplication is another exciting tool that promises to make web developers more productive, is built on Prisma and recently launched on Hacker News.

It allows to instantly generate fully-fledged REST and GraphQL APIs. The projects are configured via a web UI but can be fully customized as the underlying NestJS app can be downloaded and edited by the developer.

prisma-appsync generator

Sylvain Simao recentely released a first version of prisma-appsync, a custom generator for the Prisma schema that enables developer to generate a full-blown GraphQL CRUD API via AWS AppSync and deployable with single command of the AWS CDK.

To learn more, check out the documentation and watch our recent What's new in Prisma episode.

Our community has built custom generators for the following use cases:

Bedrock SaaS Template by Max Stoiber

Max Stoiber is well-known in the JavaScript community for his popular open source work, like styled-components and react-boilerplate.

He recently announced Bedrock, a modern full-stack boilerplate with user authentication, subscription payments, teams, invitations, emails and everything else you need to build a SaaS product. We are excited that Max chooses Prisma as his ORM for this project!


Community

We wouldn't be where we are today without our amazing community of developers. Our Slack has more than 40k members and is a great place to ask questions, share feedback and initiate discussions all around Prisma.


Join Slack

Meetups

Prisma Meetup #3
Prisma Meetup #3

Picking a database for your serverless application in 2021 - Alex DeBrie

Prisma in React Server Components - Tim Suchanek

Wasp - DSL for building web apps with Prisma, React & Node.js - Matija Šošić

GraphQL Berlin Meetup #20: Beginners Welcome! + quiz with prizes
GraphQL Berlin Meetup #20: Beginners Welcome! + quiz with prizes

GraphQL - From A to Z - Vignesh T.V.

Ramp up your GraphQL learning experience with data you already have - Stephan Schneider

GraphQL Berlin Meetup #21 + win access to Advanced React course by Wes Bos!
GraphQL Berlin Meetup #21 + win access to Advanced React course by Wes Bos!

GraphQL web components - Benny Powers

Getting Acquainted with Defer and Stream - Eve Porcello

TypeScript Berlin #5 + win a Practical Functional Programming with TS workshop!
TypeScript Berlin #5 + win a Practical Functional Programming with TS workshop!

Runtime Type Safety in Typescript - Valentin Kononov

Write Efficient & Testable code with effect-ts - Michael Arnaldi

Elm in TypeScript, pattern matching and beyond - Maciej Sikora

Advanced TypeScript Trickery - Open Mic Session #2
Advanced TypeScript Trickery - Open Mic Session #2

Prisma Enterprise Event

The Prisma Enterprise Event 2021 has been a huge success and we want to thank everyone who attended and helped making it a great experience!

We've been excited to see fantastic speakers like Pete Hunt (Twitter), Natalie Vais (Amplify Partners), James Governor (Redmonk) and DeVaris Brown (Meroxa).

The event covered a broad range of topics about the challenges large companies and enterprises face with the management of application data, such as:

  • Learn how top companies are addressing the challenges of data at scale
  • Discover how companies use Prisma to make their developers more productive
  • Get a better understanding of the future of data in the enterprise

You can get access to all the talk recordings here.


Prisma Enterprise Event 2021
Prisma Enterprise Event 2021

Opening Keynote - Søren Bramer Schmidt

Cloud Native Data: The Emergence of Enterprise Data Fabrics - James Governor

Prisma at Rapha - Tom Hutchinson

Prisma Enterprise Demo - Chris Matteson

Prisma Fireside Chat - Hervé Labas, Chris Mateson, Søren Bramer Schmidt

Building Products That Scale - Natalie Vais

Developer Experience Matters - DeVaris Brown

Tearing Down Data Silos - Hervé Labas

Evolution of Application Data Platforms – From Facebook to Twitter - Pete Hunt


Watch Talks

Stickers

We love seeing laptops that are decorated with Prisma stickers, so we're shipping sticker packs for free to our community members! In this quarter, we've sent out over 300 sticker packs to developers that are excited about Prisma!


Order Stickers

Videos, livestreams & more

What's new in Prisma

Every other Thursday, Nikolas Burk and Ryan Chenkie discuss the latest Prisma release and other news from the Prisma ecosystem and community. If you want to travel back in time and learn about a past release, you can find all the shows from this quarter here:

Videos

Prisma Chats - All About Transactions with Matt Mueller, Product Manager at Prisma
Prisma in Production: How to Load Test Your API with k6 (Daniel Norman)
Deploying a Prisma app to Vercel and setting up connection pooling with PgBouncer (Daniel Norman)

Prisma appearances

This quarter, several Prisma folks have appeared on external channels and livestreams. Here's the overview of all of them:


New Prismates

Here's an overview of the awesome new Prismates we have hired this quarter:


Vladi Stevanovic
Vladi StevanovicSr. Customer Success Manager | February 2021
😆 Fun Fact

I can cook the most amazing veggie Lasagna.

❓ Why are you joining Prisma?

I'm very excited about the product and the mission - helping developers work more efficiently with data. I'm also very interested in developing the Customer Success program and empowering Prisma users.

Chloé Votteler
Chloé VottelerOrganisational Psychologist | February 2021
😆 Fun Fact

I am not the biggest fan of ice cream and the only ice cream I would get is Pistachio 😆

❓ Why are you joining Prisma?

Prisma excites me as I realised I am going to find myself in a world of new challenges and possibilities. Working for a company like Prisma is an adventure and I am able to help create processes from scratch and develop workflows that best fit Prisma. The entrepreneurial nature undoubtably creates a lot of passion and I feel honoured to be a part of an unique experience to help build something.

Chris Matteson
Chris MattesonHead of Solutions Engineering | February 2021
😆 Fun Fact

I only felt my first earthquake last year, despite living in California. Always managed to be out of town.

❓ Why are you joining Prisma?

I joined Prisma for the same reason I joined HashiCorp in the early days, this is an enabling technology which unlocks workflows which were previously impossible. I’m honored to have a part in helping shepherd this along, as the team has already started us on a breakout path.

Julieta Curdi
Julieta Curdi Sr. Product Designer | March 2021
😆 Fun Fact

I'm a huge Harry Potter fan, in fact I own a wand 💫

❓ Why are you joining Prisma?

I'm excited about the product, the vision and the culture. I'm also excited about the opportunity to help build the Product Design practice at Prisma.

Rich Haines
Rich HainesTech Writer | March 2021
😆 Fun Fact

I majored in script writing at university and wrote a feature length film script about the greek gods in a godfather like setting

❓ Why are you joining Prisma?

The role aligned perfectly with what I want to do with my career, learn new stuff and write about it! Plus Prisma is cool, everyone knows that.

Also, we are hiring for various roles! If you're interested in joining us and becoming a Prismate, check out our jobs page.


Explore Jobs

What's next?

The best places to stay up-to-date about what we are currently working on are GitHub issues and our public roadmap.

We are currently working on a connector for MongoDB and are hoping to have an Early Access version of it ready in the next three months.

Another major area we are focusing on is the development of a cloud product that will make it easier for teams and larger organizations to collaborate on Prisma projects. To get an initial impression of what we are planning, you can watch the talks from the Prisma Enterprise Event. Stay tuned and keep an eye out for more articles on this blog in the next few weeks 👀

Join the discussion

Follow @prisma on Twitter

Don’t miss the next post!

Sign up for the Prisma newsletter