Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
APACHE-2.0 License
Bot releases are hidden (Show)
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.
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
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
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.
$transaction
API is now stableYou can now use $transaction
API without the transactionApi
feature flag.
generator client {
provider = "prisma-client-js"
- previewFeatures = ["transactionApi"]
}
connectOrCreate
API is now stableThe 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"]
}
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
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.
PrismaClient
inputs at runtimeWe 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.
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!
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.
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!
prisma
pnpm
version used for development and CIpreinstall
hook so pnpm fails clearlyprisma-client-js
language-tools
studio
prisma-engines
Published by timsuchanek almost 4 years ago
Today, we are issuing the 2.10.2
patch release.
Published by timsuchanek almost 4 years ago
Today, we are issuing the 2.10.1
patch release.
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.
This release introduces some major new features in 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
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
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
Just a quick reminder:
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.
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.
prisma
.executeRaw()
with .transaction([])
$queryRaw
and $executeRaw
in transactionsexecuteRaw
and queryRaw
atomicNumberOperations
@prisma/engines
packageprisma-client-js
Result::unwrap()
on an Err
value: Error("EOF while parsing a value", line: 1, column: 0)migrate
language-tools
studio
generator
blockprisma-engines
Xml
Decimal
Bytes
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.
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.
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.
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.
Just a quick reminder:
2.6.0
we introduced one preview feature, namely atomicNumberOperations
.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.
prisma
We can't release, as the e2e tests are not passing for the ${tag} npm tag!
checks wrong npm tag for passing e2e tests when promoting a patch-dev to latestPrismaQueryEngineError
into PrismaClientUnknownRequestError
prisma -v
should include Client version as well (if installed)prisma introspect
overwrites a 1:1 mapping as 1:manyFORCE_PANIC_INTROSPECTION_ENGINE
findFirst
should have return type Model | null
prisma-client-js
<table>WhereUniqueInput
including a column which isn't unique when composite primary key is usedprisma.$transaction
instead of a Prisma promiseSql
from @prisma/clientlanguage-tools
studio
Error: Could not find appropriate InputType for this field type. This should never happen.
Saving Changes
prisma-engines
default()
does not work in conjunction with native types@default(autoincrement())
must not be possible at the same timedebugPanic
RPC in introspection engineHuge thanks to @rahul3v for helping!
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!
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.
Published by timsuchanek about 4 years ago
Today, we are issuing the 2.8.1
patch release.
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.
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
.
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
Just a quick reminder:
2.6.0
we introduced one preview feature, namely atomicNumberOperations
.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.
prisma
set
next dev
findFirst
APIprisma-client-js
language-tools
prisma-fmt
binary path in vscode optionsstudio
prisma-engines
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!
Huge thanks to @nohns for some great contributions in this release!
Published by timsuchanek about 4 years ago
Today, we are issuing the 2.7.1
patch release.
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.
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! π
package.json
for more flexibilityPreviously, 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
Just a quick reminder:
2.6.0
we introduced one preview feature, namely atomicNumberOperations
.2.5.0
we introduced one preview feature, namely insensitiveFilters
.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.
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!
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.
prisma
--schema
argprisma init
with unknown parameter just outputs null
set
on nested update on 2.6.0introspect
command in v2.6.x does not remember cuid()
defaults for a field and user-defined @relation name
propertyintrospect --force
does not workprisma-client-js
migrate
language-tools
client/index.d.ts
should not show a notificationstudio
null
Save Changes
will always failprisma-engines
Huge thanks to @bre7, @rahul3v, @jasonkuhrt and @Weakky for helping!
Published by Jolg42 about 4 years ago
Today, we are issuing the 2.6.2
patch release.
Published by Jolg42 about 4 years ago
Today, we are issuing the 2.6.1
patch release.
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.
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
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.
Atomic number operations needs to be enabled with the feature flag atomicNumberOperations
like so:
generator client {
provider = "prisma-client-js"
previewFeatures = ["atomicNumberOperations"]
}
We are introducing five atomic operations for Int
and Float
fields :
increment: x
: Adds x
to the current valuedecrement: x
: Subtracts x
from the current valuemultiply: 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).
Just a quick reminder:
2.5.0
we introduced one preview feature, namely insensitiveFilters
.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.
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.
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.
prisma
prisma/.env
leads to confusing error messageprisma generate
stack overflow on a large schemanode_modules/.prisma/client/index.d.ts
introspect
@updatedAt
prisma-client-js
PrismaClient
constructormigrate
Error querying the database: near ",": syntax error
save
outputs connection strings if included in schema filelanguage-tools
[]
instead of ""
when using autocompletionstudio
middlewares
were removed, you can now safely remove them from your schema.prisma.prisma
not @prisma/cli
skip
can be set to negativeprisma-engines
Huge thanks to @peter50216 for helping!
Published by Jolg42 about 4 years ago
Today, we are issuing the 2.5.1
patch release.
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. π
distinct
and aggregations are now stableAfter 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!
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:
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
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
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
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
Insensitive filters querying needs to be enabled with the feature flag insensitiveFilters
like so:
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',
},
},
})
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).
middlewares
, distinct
and aggregationApi
removedAs 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.
2.1.0
Just a quick reminder:
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.
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.
prisma
Option::unwrap()
on a None
value', libs/datamodel/core/src/validator/validate.rs:178:29npx prisma introspect
errors with [libs/sql-schema-describer/src/mysql.rs:353:27] column_name
on indexes using expressions (MySQL 8.0.13+)prisma -v
npx
prefix when being triggered via npx prisma
itselfStudio
command into cli
packageTransaction
is still a reserved word in 2.4.1prisma-client-js
migrate
language-tools
studio
prisma-engines
repository_dispatch
to workflow_dispatch
to enable running branchesPublished 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.
2.4.0
// order by `age` descending and then by `name` ascending
const users = await prisma.user.findMany({
orderBy: {
age: 'desc',
name: 'asc'
}
})
2.4.1
// order by `age` descending and then by `name` ascending
const data = await client.user.findMany({
orderBy: [
{
age: 'desc',
},
{
name: 'asc',
},
],
})
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 π
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
$
dollar prefix for top-level Prisma Client methodsIn 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:
$disconnect
$connect
$on
$queryRaw
$executeRaw
$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.
With this release, we shipped a number of improvements for Prisma Studio:
Try out Prisma Studio in the online demo or in your Prisma project by running:
npx prisma studio --experimental
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()
2.1.0
, 2.2.0
, and 2.3.0
Just a quick reminder:
2.1.0
we introduced two experimental features, namely connectOrCreate
and transactionApi
.2.2.0
we introduced aggregateApi
.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.
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.
prisma
@default("")
for String fieldsCreateInput
and UpdateInput
have different typings for optional relations@relation
field after introspectionoutput
is specified on generator
@@map
and @map
with argument name
loses the name
after re-introspection@map
will get option commented if it invalid without map{ where: { non_fk_field: null } }
prisma-client-js
migrate
language-tools
studio
prisma-engines
Published by timsuchanek about 4 years ago
Today, we are issuing the 2.3.0
stable release.
The Prisma VS Code extension now helps you rename models, fields and enums:
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.
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 = ["..."]
}
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
Distinct querying needs to be enabled with the feature flag discintApi
like so:
generator client {
provider = "prisma-client-js"
previewFeatures = ["distinct"]
}
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).
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
Middlewares need to be enabled with the feature flag middlewares
like so:
generator client {
provider = "prisma-client-js"
previewFeatures = ["middlewares"]
}
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).
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.
prisma
file:
is what works and sqlite:
sqlite://
should errorwhere
prisma -v
previewFeatures
as replacement for experimentalFeatures
prisma-client-js
select
migrate
migrate.lock
file to avoid git history messenv("DATABASE_URL")
freezes migrationsid
)language-tools
post
on Model foo
must specify the fields
argument in the @relation directive."@default
attributes when they are functionsstudio
0
instead of null
prisma-engines
@default(autoincrement())
Huge thanks to @RafaelKr for helping!
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
Published by Jolg42 over 4 years ago
Today, we are issuing the 2.2.1
patch release.
where
#2959 Published by janpio over 4 years ago
Today, we are issuing the 2.2.0
stable release.
Next to a lot of bug fixes, this version includes a number of new features!
The Prisma VS Code extension now helps you fix any accidental typos and offers more convenient "Quick Fixes" right inside your editor.
provider
dynamic via environment variablesThe 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")
}
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.
We were able to continue to improve the re-introspection flow based on your feedback. Thanks!
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.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.
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).
prisma
prisma generate
throws exit code 0 in case of error caused by denied keywordsprisma migrate (save | up | down) --schema <file-path>
prisma-client-js
count
requests result in Invalid prisma.web_hooks.count invocation
create
and delete
migrate
migrate up
tells me to read in ./migrations/MIGRATION_ID/README.md
migrate save/up
hangs while creating databaseREADME.md
of migration folder includes quaint
in SQL@default(now())
so that it only can be used in DateTime fieldsvscode
***
in GH action outputstudio
prisma-engines