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
- [Re-Introspection] Keep order of models of existing Prisma schema
- Sort fields by the user's defined order not alphanumerically
- Add minimal integration test for studio
- Default value for relations
- Supporting querying distinct rows
- Omit full path when running prisma --version
- (Re)Introspection does not respect variables in dotenv file when schema is located in a custom directory
- Use denylist in Introspection already
- Clarify usage of datasource url when using SQLite -
file:
is what works andsqlite:
sqlite://
should error - Postinstall hook fails with custom location for schema.prisma
- [Introspection] Pick up order of columns in database into schema
- Aggregate function is missing typing for
where
- [2.2] Not loading ./prisma/.env variables when ./.env exists
- Rename the following items: - "model Transaction" after upgrade from 2.1 to 2.2
- Output feature flags in
prisma -v
- Add
previewFeatures
as replacement forexperimentalFeatures
prisma-client-js
- Investigate Amazon RDS Proxy
- Improve automatically generated error reports
- The ID's/techinique used to looked up nest relationships differs and results in a PANIC error, depending on what fields are included or not included in a
select
- Middlewares
- Enum value 'false' breaks Prisma client create
migrate
- Add linebreak at the end of
migrate.lock
file to avoid git history mess - Using
env("DATABASE_URL")
freezes migrations - Changing IDs in explicit n-m relationship results in no change
- @prisma/migrate makes react types required
- Abort on unexecutable migrations
- Null constraint violation on the fields: (
id
) - @prisma/cli calling migrate save with a prisma schema error hangs indefinitely
language-tools
- "Error parsing attribute "@@relation": The relation field
post
on Modelfoo
must specify thefields
argument in the @relation directive." - Add Rename Helper Tool
- Try to execute the binary in the "is binary download needed?" check
- Keep root package.json version in sync with subfolders
- LSP should have its own test cases
- Separate vscode text/links from language server
- Check existing LSP version in CI before publishing
- CI fails if master changes during the run
- Validation for values of
@default
attributes when they are functions - Put caret into created model or enum after creating it via quick-fix
- Add quick-fix gif to README
- @updatedAt not showing up for auto-completion
- Auto-completion adds too many quotation marks
- Formatter not working: Cannpt execute binary file
studio
- How to navigate to related records?
- Loading state shows column titles later than actual empty table
- Console is full with ag-grid warnings
- Text editing operations shouldn't change based on data type
- Consider removing the delete button
- Can't select a related row in "add row" dialog
- Deleting required relation crashes
- Table view doesn’t show new field
- Adding relation in new record won’t load more than one record in other table
- Int fields are
0
instead ofnull
prisma-engines
- Check whether the ForeignKeyDefaultDrop destructive change check is still needed
- [Introspection] Comment out Models that do not have a strict unique criteria
- Rust cuid() implementation may output more than 25 characters
- Examine our implementation of CUIDs
- Forbid to update int fields that are
@default(autoincrement())
- Parser Refactoring: Split Field type into RelationField and ScalarField
Credits
Huge thanks to @RafaelKr for helping!