prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

APACHE-2.0 License

Downloads
64.3M
Stars
39.2K
Committers
259

Bot releases are hidden (Show)

prisma - 2.11.0

Published by timsuchanek almost 4 years ago

Today, we are excited to share the 2.11.0 stable release πŸŽ‰

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

Major Improvements

Native database types in the Prisma schema (Preview)

We are super excited to share that this release brings you one of the most requested features since we released the initial version of Prisma: The representation of native database types in the Prisma schema.

Up to this release, the Prisma schema only allowed to represent a limited set of types: String, Int, Float, Boolean, DateTime, Json. Each of these types has a default mapping to an underlying database type that's specified for each connector (see the mappings for PostgreSQL and MySQL).

With this release, you can now add an attribute to a field definition in order to determine which specific database type it should be mapped to. Here is an example for a PostgreSQL database that specifies the underlying database types more specifically. Note that you also need to enable the feature via the the nativeTypes feature flag:

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

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

model User {
  id    Int     @id @default(autoincrement()) 
  name  String? @db.VarChar(255)
}

model Post {
  id        Int      @id @default(autoincrement()) 
  title     String   @db.VarChar(100)
  createdAt DateTime @db.Timestamp(6)
  wordCount Int      @db.SmallInt
}

In the above code snippet, all fields of the two Prisma models are annotated with attributes to diverge from the default mapping and determine the exact type that is used in the underlying database. For example, the id fields are represented as db.BigInt which maps to the BIGINT PostgreSQL type. You can find out more about which Prisma types can be annotated with which native type attributes in the docs for the PostgreSQL and MySQL connectors.

Note: Native types don't work with Prisma Migrate yet. For the time being, you still need to configure the type manually in your database and pull it into your schema via introspection.

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

πŸ“š Documentation: Extended native type support

New types in the Prisma schema: BigInt, Bytes and Decimal (Preview)

With this release, we are further introducing three new scalar types in the Prisma schema: BigInt, Bytes and Decimal. Here is an overview for how they map to the different databases that are supported by Prisma and how they're represented when queried with Prisma Client JS:

Prisma PostgreSQL MySQL SQLite JavaScript / TypeScript
Bytes BYTEA LONGBLOB n/a Buffer
Decimal DECIMAL(65,30) DECIMAL(65,30) n/a Decimal.js
BigInt BIGINT BIGINT n/a BigInt

To make use of these new types, you need to enable the nativeTypes feature flag in your Prisma schema:

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

Once you added the feature flag, be sure to run prisma generate again to update your local version of Prisma Client.

πŸ“š Documentation: Prisma types in the nativeTypes preview

Set foreign keys directly (Preview)

We now support writing foreign keys (also known as relation scalars) directly with the uncheckedScalarInputs preview feature.

Consider this sample Prisma schema:

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

model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}

model Post {
  id       Int  @id @default(autoincrement())
  authorId Int
  author   User @relation(fields: [authorId], references: [id])
}

Instead of using connect when creating a new Post record to wire up a relation with a User record, you can now directly set the authorId value:

await prisma.post.create({
  data: {
    // You can now set the foreign key directly...
    authorId: 1,
    // ... or connect the relationship...
    // author: {
    //   connect: {
    //     id: 1
    //   }
    // }
    // ... but not both at the same time
  },
});

We'd love for you to give it a try. You can give us feedback in this issue.

The $transaction API is now stable

You can now use $transaction API without the transactionApi feature flag.

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

The connectOrCreate API is now stable

The connectOrCreate API offers a convenient way to link or insert nested records.

You can now use it without the connectOrCreate feature flag.

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

Middleware model parameter is now typed

This is a small quality-of-life improvement for developers using the Prisma middleware. The params.model parameter that's passed into a middleware function is now typed to your model so you can now reliably tie middleware to models:

prisma.$use(async (params, next) => {
  switch (params.model) {
    case 'user':
      // ...
    case 'project:
      // ...
  }
})

If you need the old behavior you can cast params.model back to a string by wrapping it String(params.model).

πŸ“š Documentation: Middleware

Deprecation of multi-provider array

You will now see a warning if you have multiple providers in your datasource. We recently realized that supporting an array of providers in the Prisma schema was premature, adding complexity in the process of improving the product, and causing some confusion about our intent.

You can read more about the decision and what to do about it in this issue.

Validate PrismaClient inputs at runtime

We now validate the parameters we accept in new PrismaClient(parameters). This is unlikely to affect you unless you were passing invalid parameters into PrismaClient before.

Prisma Client Go is now Early Access πŸŽ‰

We're happy to announce that Prisma Client Go has graduated from experimental to Early Access.

You can get started here. We'd love to learn more about how you use the Go Client during Early Access. You can schedule a call with us or chat with us on Slack in the #prisma-client-go channel. We're looking forward to hearing from you!

πŸ“Ί 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 12 at 5pm Berlin | 8am San Francisco.

πŸ‘€ Make your online talk recordings more accessible with subtitles

We'd love to help you make your talk recordings (no matter if Meetup or conference talk) more accessible by adding subtitles to it for free! Reach out to [email protected] if you are interested in getting subtitles for your videos!

Fixes and improvements

prisma

prisma-client-js

language-tools

studio

prisma-engines

prisma - 2.10.0

Published by nikolasburk almost 4 years ago

Today, we are excited to share the 2.10.0 stable release πŸŽ‰

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

Major improvements

This release introduces some major new features in Preview!

Support for Microsoft SQL Server (Preview)

With this release, we're introducing support for a new database: Microsoft SQL Server πŸ₯³

You can start using your MS SQL Server databases today with introspection and query them with Prisma Client. Note that Prisma Migrate does not support MS SQL Server yet.

An MS SQL Server database is specified in your Prisma schema via the new sqlserver connector. Note that while it's in Preview, you also need to add the additional previewFeature flag microsoftSqlServer in the generator for Prisma Client:

datasource db {
  provider = "sqlserver"
}

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

You can find a ready-to-run example based on MS SQL Server here.

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know whether this feature is already ready for production! (If you encounter any problems, please open a new issue here).

πŸ“š Documentation: Microsoft SQL Server connector

Single-command schema changes for prototyping (Preview)

With this release, we are introducing a new command that lets you push the state of your Prisma schema file to the database without using migrations: prisma db push --preview-feature

push is the first command that's introduced under the new prisma db namespace. The prisma db namespace will be used for commands that operate directly against the database without e.g., saving or manipulating a migration history on your file system nor in the migrations table. It's therefore well-suited for prototyping and local development environments. In production environments, you'll want to be able to track and replay the changes made to your database which will be handled by the prisma migrate namespace.

The idea behind prisma db push is that you only care about the end state of your database schema, but not about how this end state is achieved.

Also note that the command runs prisma generate for you, so you're saving an extra step after having updated your Prisma schema!

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know whether this feature is already ready for production! (If you encounter any problems, please open a new issue here).

πŸ“š Documentation: db push command

Atomic number operations are now stable

In 2.6.0 we introduced case atomic number operations in Preview, in today's release we're promoting this feature to stable. This means you don't need to include the atomicNumberOperations feature flag in the Prisma Client generator any more:

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

πŸ“š Documentation: Atomic operations on update

Already existing preview features from previous releases

Just a quick reminder:

  • In version 2.1.0 we introduced two preview features, namely connectOrCreate and transactionApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

πŸŽƒ Join the first Prisma Meetup online

We are excited to bring you the first Prisma Meetup which is going to happen entirely online, so you can dial in from around the globe!

It will be streamed on Youtube this Thursday: October 29th, 2020 at 6pm (CET, Berlin) | 10am (PDT, San Francisco)

We have amazing speakers on board for our first Meetup:

β—­ Tammy Butow (Principal SRE @ Gremlin): Database Horror Stories
β—­ HervΓ© Labas (VP of Product @ Prisma): The future of Prisma and its roadmap
β—­ Tom Hutchinson (Head of Mobile @ Rapha): Prisma at Rapha

You can watch the event on YouTube here.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

prisma - 2.9.0

Published by timsuchanek about 4 years ago

Today, we are excited to share the 2.9.0 stable release πŸŽ‰

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

Improvements

In today's release, we have many bug fixes, increased test coverage, and improved error messages. The release also lays the foundations for the upcoming native database types support.

Errors thrown by Prisma Client include the version

With this release, error objects thrown by Prisma Client include the clientVersion field which contains the version of Prisma Client. This is useful for debugging and creating issues.

Improved error message of prisma.$transaction

When you use prisma.$transaction to group multiple calls into a single transaction, you need to pass an array of promises. Passing calls that have been awaited will now trigger a more helpful error:

Error: All elements of the array need to be Prisma Client promises. Hint: Please make sure you are not awaiting the Prisma client calls you intended to pass in the $transaction function.

Already existing preview features from previous releases

Just a quick reminder:

  • In version 2.6.0 we introduced one preview feature, namely atomicNumberOperations.
  • In version 2.1.0 we introduced two preview features, namely connectOrCreate and transactionApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

Issues closed with the release

prisma

prisma-client-js

language-tools

studio

prisma-engines

Credits

Huge thanks to @rahul3v for helping!

Interested in providing feedback for the upcoming version of Prisma Migrate?

We are seeking users interested in trying out upcoming versions of Prisma Migrate. This will involve trying it out, validating functionality, and sharing feedback with us.

If you're interested in participating, fill out the following form, it won't take longer than a minute!

πŸŽƒ Join the first Prisma Meetup online

We are excited to bring you the first Prisma Meetup which is going to happen entirely online, so you can dial in from around the globe!

The Meetup will be streamed on Youtube this Thursday: October 29th, 2020 at 6pm (CET, Berlin) | 10am (PDT, San Francisco)

We have amazing speakers on board for our first Meetup:

β—­ Tammy Butow (Principal SRE @ Gremlin): Database Horror Stories
β—­ HervΓ© Labas (VP of Product @ Prisma): The future of Prisma and its roadmap
β—­ Tom Hutchinson (Head of Mobile @ Rapha): Prisma at Rapha

You can watch the event on YouTube here.

prisma - 2.8.0

Published by timsuchanek about 4 years ago

Today, we are excited to share the 2.8.0 stable release πŸŽ‰

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

Major improvements

In today's release, we have two new features coming for you!

findFirst

While the findMany API gives you a powerful API to query your database with different filters, it's not ideal if you just want to query a single item.

On the other hand, the findOne API returns single items, but it only allows for filtering by unique fields.

In version 2.8.0, we introduce findFirst - giving you the full power of findMany filters while only returning the first item that matches the filter criteria.

So instead of this:

const usersCalledAlice = await prisma.user.findMany({
  name: "Alice"	
})
const firstUserCalledAlice = usersCalledAlice[0]

You can now do this:

const firstUserCalledAlice = await prisma.user.findFirst({
  name: "Alice"	
})

All filters available for findMany are also available in findFirst.

Case insensitive filters for PostgreSQL are now stable

In 2.5.0 we introduced case insensitive filters for PostgreSQL, in today's release we're promoting this feature to stable. This means you don't need to include the insensitiveFilters feature flag in the Prisma Client generator any more:

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

The new mode option you can pass to findMany influences the corresponding filter (e.g. contains or startsWith) but doesn't change the return type of the findMany query. mode can have two possible values:

  • default: Uses the default filter configured on the database level. If the collation is configured as case insensitive in the database, the default mode will be case insensitive as well. In that case, there's no need to use the insensitive mode.
  • insensitive: Uses the case insensitive filter (if possible).
const result = await prisma.user.findMany({
  where: {
    email: {
      equals: '[email protected]',
      mode: 'insensitive',
    },
  },
})

Note that this feature will not work if you're using database collations that do not know how to convert between upper- and lowercase letters (e.g. the C collation).

πŸ“š Documentation: Case sensitivity / Case-sensitive filtering

Already existing preview features from previous releases

Just a quick reminder:

  • In version 2.6.0 we introduced one preview feature, namely atomicNumberOperations.
  • In version 2.1.0 we introduced two preview features, namely connectOrCreate and transactionApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

Fixes and improvements

prisma

prisma-client-js

language-tools

studio

prisma-engines

❓ Are you using Prisma at work?

We'd love to know if you're using Prisma at work. Answer with a quick yes or no in our poll, it won't take longer than a few seconds!

Credits

Huge thanks to @nohns for some great contributions in this release!

prisma - 2.7.1

Published by timsuchanek about 4 years ago

prisma - 2.7.0

Published by timsuchanek about 4 years ago

Today we are excited to share the 2.7.0 stable release.

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

Major improvements

Prisma Studio is stable πŸŽ‰

We are more than excited to share that Prisma Studio has moved out of its experimental state and is promoted to stable with today's release! Prisma Studio is the perfect companion for developers who work with databases in their daily workflows, to quickly get an overview of the state of their database as well as to view and modify the data in it. An announcement blog post will be coming soon!

To use Prisma Studio in your Prisma project, you can now run the prisma studio command without the previously required --experimental flag:

npx prisma studio

Join the #prisma-studio channel in the Prisma Slack and let us know how you like Prisma Studio! πŸ™Œ

Configure Prisma schema location via package.json for more flexibility

Previously, your schema.prisma file needed to be available at a specific location when running Prisma CLI commands or provided via the --schema option when invoking a Prisma CLI command.

With this release, you can configure the location of your Prisma schema via a prisma property in your package.json:

{
  "prisma": {
    "schema": "path/to/schema.prisma"
  }
}

The provided location in package.json will be the default location of the Prisma schema file for any Prisma CLI command you invoke. Note that you can still override this default location by manually specifying the --schema option when invoking a Prisma CLI command.

πŸ“š Documentation: Prisma schema file location

Already existing preview features from previous releases

Just a quick reminder:

  • In version 2.6.0 we introduced one preview feature, namely atomicNumberOperations.
  • In version 2.5.0 we introduced one preview feature, namely insensitiveFilters.
  • In version 2.1.0 we introduced two preview features, namely connectOrCreate and transactionApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

Feedback wanted: How does introspection work for you?

In the last few releases we improved Prisma's database introspection, most notably with "More robust introspection by keeping manual changes in the Prisma schema file" but also many smaller bug fixes. We think it is pretty stable now, and would love to hear from you, our users, how you have been using prisma introspect recently!

If you have used introspection in the past, whether it worked well or not so well with your database, please let us know by sharing your feedback on GitHub!

🌟 Help us spread the word about Prisma

To help spread the word about Prisma, we'd very much appreciate if you would star this repo 🌟 And if you're excited about the features in this week's release, then help us and share it on Twitter.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

Credits

Huge thanks to @bre7, @rahul3v, @jasonkuhrt and @Weakky for helping!

prisma - 2.6.2

Published by Jolg42 about 4 years ago

Today, we are issuing the 2.6.2 patch release.

Fixes

Prisma Client JS

prisma - 2.6.1

Published by Jolg42 about 4 years ago

Today, we are issuing the 2.6.1 patch release.

Fixes

Prisma Client JS

prisma - 2.6.0

Published by Jolg42 about 4 years ago

Today we are excited to share the 2.6.0 stable release.

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

Major improvements

More robust introspection by keeping manual changes in the Prisma schema file

In prior releases, any manual changes to your Prisma schema would be overridden when invoking prisma introspect (e.g. usage of @map or @@map as well as the renaming of relation fields).

Keeping these manual changes in the Prisma schema file has been available as a preview feature via the --experimental-reintrospection already. After getting tested as a preview feature for a few releases, we are excited to promote this functionality to be the default behavior of prisma introspect into this stable release.

Note that you can opt-out of this behavior by using the new --force flag: prisma introspect --force. This will generate a schema purely based on the introspected database and override any prior manual changes.

πŸ“š Documentation: Prisma Introspect

Preview features

New: Atomic number operations on update

With today's release, we introduce atomic number operations for update queries in Prisma Client. It allows you to update the values of certain fields atomically.

Feature flag

Atomic number operations needs to be enabled with the feature flag atomicNumberOperations like so:

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

Usage

We are introducing five atomic operations for Int and Float fields :

  • increment: x: Adds x to the current value
  • decrement: x: Subtracts x from the current value
  • multiply: x: Multiplies the current value by x
  • divide: x: Divides the current value by x
  • set: x: Sets the value to x (equivalent to data: { age: 18 })

Note: Only one operation can be done per field at a time.

Here's an example of using the new operations:

const result = await prisma.user.update({
  where: {
    email: '[email protected]',
  },
  data: {
    points: {
      set: 99, // this just sets the value, equivalent to `data: { points: 18 }`
    },
    age: {
      increment: 1, // age = age + 1 - Happy Birthday!
    },
    credits: {
     decrement: 2, // credits = credits - 2
    },
    karma: {
      multiply: 3, // karma = karma * 3
    },
    chocolates: {
      divide: 4, // chocolates = chocolates / 4
    },
  },
})

πŸ“š Documentation: Atomic operations on update

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

Already existing preview features from previous releases

Just a quick reminder:

  • In version 2.5.0 we introduced one preview feature, namely insensitiveFilters.
  • In version 2.1.0 we introduced two preview features, namely connectOrCreate and transactionApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

πŸ€” How would you describe Prisma?

We'd love to hear from you how you describe Prisma to your developer friends and coworkers. If you have 2 minutes, please answer this question via this online form.

🌟 Help us spread the word about Prisma

To help spread the word about Prisma, we'd very much appreciate if you would star this repo 🌟 And if you're excited about the features in this week's release, then help us and share it on Twitter.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

Credits

Huge thanks to @peter50216 for helping!

prisma - 2.5.1

Published by Jolg42 about 4 years ago

prisma - 2.5.0

Published by Jolg42 about 4 years ago

Today we are excited to share the 2.5.0 stable release.

🌟 Help us spread the word about Prisma by starring the repo ☝️, tweeting about the release or sharing your experience with Prisma on Reddit. 🌟

Major improvements

Middlewares, removing duplicates with distinct and aggregations are now stable

After running in preview mode for a number of releases, we are excited to promote the following features into this stable release:

  • middlewares
  • distinct
  • aggregateApi

This means you can omit the respective feature flags in the generator block in your Prisma schema:

generator client {
  provider        = "prisma-client-js"
- previewFeatures = ["middlewares", "distinct", "aggregateApi"]
}

Read on to learn about each feature individually!

Middlewares

Prisma Client's middleware lets you intercept Prisma Client queries to manipulate its parameters and interrogate its result. A middleware is a function that's passed to Prisma Client's $use method.

Middlewares are convenient for a number of use cases, for example:

  • Logging the time taken to perform a type of query
  • Manipulating or validating query parameters
  • Contacting another service upon specific queries

The following example includes two middlewares:

const prisma = new PrismaClient()

prisma.$use(async (params, next) => {
  const result = next(params);
  return result;
}

prisma.$use(async (params, next) => {
  return next(params);
}

πŸ“š Documentation: Middleware

Remove duplicates from query results with distinct

Prisma Client allows you to filter duplicate rows from the response to a findMany query using the distinct option:

const distinctCities = await prisma.user.findMany({
  select: {
    city: true,
    country: true,
  },
  distinct: ["city"],
});

πŸ“š Documentation: Distinct

Aggregations with aggregate

Prisma Client allows you to perform aggregations operations on the number fields (such as Int and Float) of a model - for example, you can get the average age of all users:

const aggregations = await prisma.user.aggregate({
  avg: {
    age: true,
  },
});

console.log("Average age:" + aggregations.avg.age);

Prisma Client supports the following aggregations:

  • avg (average)
  • sum (sum)
  • min (minimum value)
  • max (maximum value)

πŸ“š Documentation: Aggregations

Preview features

New: Case insensitive filters (PostgreSQL only)

In 2.5.0 we introduce case insensitive filters for querying capabilities to Prisma Client. It allows you to query for fields in a case insensitive way.

Note: This feature will not work if you're using database collations that do not know how to convert between upper- and lowercase letters (e.g. the C collation).

πŸ“š Documentation: Case sensitivity / Case-sensitive filtering

Feature flag

Insensitive filters querying needs to be enabled with the feature flag insensitiveFilters like so:

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

Usage

The new mode option you can pass to findMany influences the corresponding filter (e.g. contains or startsWith) but doesn't change the return type of the findMany query. mode can have two possible values:

  • default: Uses the default filter configured on the database level. If the collation is configured as case insensitive in the database, the default mode will be case insensitive as well. In that case, there's no need to use the insensitive mode.
  • insensitive: Uses the case insensitive filter (if possible).
const result = await prisma.user.findMany({
  where: {
    email: {
      equals: '[email protected]',
      mode: 'insensitive',
    },
  },
})

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

Feature flags for middlewares, distinct and aggregationApi removed

As mentioned above, we were able to promote three features into this stable release. This was thanks to your help and feedback, so please keep trying the preview features if they're useful to you and help us by sharing feedback.

Already existing preview features from 2.1.0

Just a quick reminder:

  • In version 2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

🌟 Help us spread the word about Prisma

To help spread the word about Prisma, we'd very much appreciate if you would star this repo 🌟 And if you're excited about the features in this week's release, then help us and share it on Twitter.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

prisma - 2.4.1

Published by timsuchanek about 4 years ago

Today, we are issuing the 2.4.1 patch release.

When we released the new "Order by multiple fields" feature, you gave us feedback, that the order of properties is not stable in JavaScript. Since ES2015 that is not a problem in the language itself anymore.
However, some teams use the eslint sort-keys plugin, which sorts the keys of objects by alphabet.

Therefore we decided to change the API in a patch release to minimize any problems this might cause to you.

Order by multiple fields in 2.4.0

// order by `age` descending and then by `name` ascending
const users = await prisma.user.findMany({
  orderBy: {
    age: 'desc',
    name: 'asc'
  }
})

Order by multiple fields in 2.4.1

// order by `age` descending and then by `name` ascending
const data = await client.user.findMany({
  orderBy: [
    {
      age: 'desc',
    },
    {
      name: 'asc',
    },
  ],
})
prisma - 2.4.0

Published by timsuchanek about 4 years ago

Today, we are issuing the 2.4.0 stable release.

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

Major improvements

Order by multiple fields

A long-awaited feature - the ability to order by multiple fields in Prisma Client is finally here!

Until now you could only order by a single scalar field of a model. The API design however was already prepared for ordering multiple fields with the object syntax we have. Instead of just one property, that orderBy object can now have as many fields as you want! The order of the fields hereby determines the order of the returned list (see example below).

Note: As this is an incremental change in the API, we introduce this feature without a feature flag.

You can use it like so:

// order by `age` descending and then by `name` ascending
const users = await prisma.user.findMany({
  orderBy: {
    age: 'desc',
    name: 'asc'
  }
})

As mentioned by the comment, the returned objects in users are ordered first by age (descending), and then by name (ascending).

πŸ“š Documentation: Sort on multiple fields

Top-level Client Methods: $ dollar prefix for top-level Prisma Client methods

In recent versions, we introduced a couple of top-level methods in Prisma Client (e.g. prisma.transaction() and prisma.use()) in preview mode. The immediate feedback was that the denylist for model names grew - which breaks Prisma schemas where a model is called Transaction, transaction, use, or Use. And the list goes on...

In order to have a future-proof API, that allows maximum expressibility in terms of model names, we decided to prefix all non-query methods with a dollar sign $. That means Prisma Client will from now on ship with the following methods:

Pre-existing

  • $disconnect
  • $connect
  • $on
  • $queryRaw
  • $executeRaw

Still in preview

  • $use
  • $transaction

The preview methods have already been renamed, the pre-existing methods like connect are still available, you just get a deprecation warning. They will be available for a few more releases with an alias, so no hurry to update them yet.

Updates in Prisma Studio

With this release, we shipped a number of improvements for Prisma Studio:

  • Refreshed design
  • Moved the Reload button from the right of the databrowser to the left
  • Moved the Pending Actions bar from the bottom of the databrowser to the top right
  • Removed the sidebar; to open a model, you can now press the New Tab button on the top
  • Removed the code editor
  • Removed the tree view
  • Added ability to view and edit JSON fields

Try out Prisma Studio in the online demo or in your Prisma project by running:

npx prisma studio --experimental

Preview features

Changes to middlewares and transactionApi

As mentioned above, we ar changing the names of some the top-level Prisma Client methods. This affects the two preview features middlewares and transactionApi.

middlewares

You still need to enable the preview feature via the generator block in your Prisma schema to access it:

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

Before

prisma.on()

After

prisma.$on()
transactionApi

You still need to enable the preview feature via the generator block in your Prisma schema to access it:

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

Before

prisma.transaction()

After

prisma.$transaction()

Already existing preview features from 2.1.0, 2.2.0, and 2.3.0

Just a quick reminder:

  • In version 2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi.
  • In 2.2.0 we introduced aggregateApi.
  • In 2.3.0 we introduced middlewares and the distinctApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

🌟 Help us spread the word about Prisma

To help spread the word about Prisma, we'd very much appreciate if you would star this repo 🌟 And if you're excited about the features in this week's release, then help us and share it on Twitter.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

prisma - 2.3.0

Published by timsuchanek over 4 years ago

Today, we are issuing the 2.3.0 stable release.

Major improvements

Rename helper tool in VS Code Extension

The Prisma VS Code extension now helps you rename models, fields and enums:

Introspection uses order of columns in table to order fields in model

prisma introspect until recently ordered all fields in models alphabetically. Starting with 2.3.0 it now picks up the order from the columns in your database table and uses that same order for the fields in your models in your Prisma schema file.

Preview features

Renaming "Experimental features" to "Preview features"

With 2.1.0 we introduced feature flags for Prisma Client, called "Experimental Features". The property in the schema has been renamed from experimentalFeatures to previewFeatures to better communicate what they actually are.

generator client {
   provider             = "prisma-client-js"
-  experimentalFeatures = ["..."]
+  previewFeatures      = ["..."]
}

New: Distinct API

In 2.3.0 we introduce distinct querying capabilities to Prisma Client. It allows you to query for distinct (unique) rows of a model. In other words: The fields you provide in the distinct argument will be duplicate free.

πŸ“š Documentation: Distinct

Feature flag

Distinct querying needs to be enabled with the feature flag discintApi like so:

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

Usage

Distinct is only a filter and doesn't change the return type of the findMany query.

const result = await prisma.user.findMany({
  where: {},
  distinct: ['name']
})

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

New: Middlewares API

In 2.3.0 we introduce a Middlewares API as a preview feature. It allows you to hook into the control flow of Prisma Client.

πŸ“š Documentation: Middleware

Feature flag

Middlewares need to be enabled with the feature flag middlewares like so:

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

Usage

Here is an example that prints the execution time of a query made by Prisma Client:

const client = new PrismaClient()

client.use(async (params, next) => {
  console.log('params', params)
  const before = Date.now()
  const result = await next(params)
  const after = Date.now()
  console.log(`Query ${params.model}.${params.action} took ${after - before}ms`)
  return result
})

const data = await client.user.findMany({})

This will log the following:

params {
  args: {},
  dataPath: [],
  runInTransaction: false,
  action: 'findMany',
  model: 'User'
}

Query User.findMany took 2ms

Middlewares allow you to both manipulate the params and the result.

They are called in an "onion" fashion. If you have multiple middlewares, this is the order of things being called:

const client = new PrismaClient()

client.use(async (params, next) => {
  console.log('1')
  const result = await next(params)
  console.log('4')
  return result
})

client.use(async (params, next) => {
  console.log('2')
  const result = await next(params)
  console.log('3')
  return result
})

Prints:

1
2
3
4

While Prisma Client's middlewares work a bit different, they're by inspired Koa's middlewares.

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

Already existing preview features from 2.1.0 and 2.2.0

Just a quick reminder: In version 2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi.
In 2.2.0 we introduced aggregateApi.

In case they're useful for you, please give them a try and let us know! They stay in preview in this release.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

Credits

Huge thanks to @RafaelKr for helping!

prisma - 2.2.2

Published by Jolg42 over 4 years ago

Today, we are issuing the 2.2.2 patch release.

With 2.2.1 the wrong binary was released, this new patch fixes it.

The new binary hash from npx @prisma/[email protected] -v is a9e8c3d97ef2a0cf59256e6b26097f2a80f0a6a4

prisma - 2.2.1

Published by Jolg42 over 4 years ago

Today, we are issuing the 2.2.1 patch release.

Fixes and improvements

Prisma CLI

Prisma Client JS

Studio

  • Bug fixes
prisma - 2.2.0

Published by janpio over 4 years ago

Today, we are issuing the 2.2.0 stable release.

Major improvements

Next to a lot of bug fixes, this version includes a number of new features!

Quick fix suggestions in Prisma VSCode Extension

The Prisma VS Code extension now helps you fix any accidental typos and offers more convenient "Quick Fixes" right inside your editor.

Make datasource provider dynamic via environment variables

The provider field on the datasource defininitions in your Prisma schema now also accepts an array of strings (instead of just a plain string). This can be helpful when you want to switch environments which point to different databases based on an environment variable. Learn more about this feature here.

datasource db {
  provider = ["sqlite", "postgres"]
  url      = env("DATABASE_URL")
}

Experimental features

Already existing experimental features

Just a quick reminder: In v2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi. In case they're useful for you, please give them a try! They stay experimental in this release.

Re-Introspection

We were able to continue to improve the re-introspection flow based on your feedback. Thanks!

Aggregations API

While Prisma Client already provides a count query for each model, we now introduce further aggregation functionality for number fields.

If your model has a field of type Int or Float, the following aggregations will be available:

  • sum: Sum up all values of a field for the selected rows.
  • min: Get the minimum value for a field for the selected rows.
  • max: Get the maximum value for a field for the selected rows.
  • avg: Get the average value for a field for the selected rows.

Example

Note, that the count API is always available, while sum, min, max, and avg are only available for a model if it has a number field.

Feature flag

In order to enable this experimental feature, note that you need to set the feature flag aggregateApi in the Prisma Client generator block in your schema:

generator client {
  provider = "prisma-client-js"
  experimentalFeatures = ["aggregateApi"]
}

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

Fixes and improvements

prisma

prisma-client-js

migrate

vscode

studio

prisma-engines

Package Rankings
Top 0.41% on Npmjs.org
Top 17.22% on Repo1.maven.org
Top 3.78% on Proxy.golang.org
Badges
Extracted from project README
Prisma Tests Status Ecosystem Tests Status