Skip to content

Commit

Permalink
Merge branch 'main' into varchar
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch authored Dec 23, 2024
2 parents e26645f + 0cd813f commit 3cdf73e
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ const relationCount = await prisma.user.findMany({

When you use `select` or `include` to return a subset of the related data, you can **filter and sort the list of relations** inside the `select` or `include`.

For example, the following query returns all users and a list of titles of the unpublished posts associated with each user:
For example, the following query returns list of titles of the unpublished posts associated with the user:

```ts
const result = await prisma.user.findFirst({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,22 @@ const user = await xprisma.user.findFirstOrThrow({
})
```
In this case, omitting both `password` and `sanitizedPassword` will exclude both from the result as well as prevent the `password` field from being read from the database.

## Limitation
As of now, Prisma Client's result extension component does not support relation fields. This means that you cannot create custom fields or methods based on related models or fields in a relational relationship (e.g., user.posts, post.author). The needs parameter can only reference scalar fields within the same model. Follow [issue #20091 on GitHub](https://github.com/prisma/prisma/issues/20091).


```ts
const prisma = new PrismaClient().$extends({
result: {
user: {
postsCount: {
needs: { posts: true }, // This will not work because posts is a relation field
compute(user) {
return user.posts.length; // Accessing a relation is not allowed
},
},
},
},
})
```
13 changes: 13 additions & 0 deletions content/300-accelerate/250-connection-pooling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ Accelerate has a default global timeout of `15s` for each [interactive transacti

See the [troubleshooting guide](/accelerate/troubleshoot#p6004-querytimeout) and our [pricing page](https://www.prisma.io/pricing#accelerate) for more information.

When you set a higher interactive transaction timeout in the Prisma Console, you **must also** specify a matching `timeout` value in your interactive transaction query via timeout [transaction option](/orm/prisma-client/queries/transactions#transaction-options). Otherwise, transactions will still time out at the lower default (e.g., 5 seconds limit when no timeout value is specified). Here’s an example of how to set a 30-second timeout in your code:

```ts
await prisma.$transaction(
async (tx) => {
// Your queries go here
},
{
timeout: 30000, // 30s
}
);
```

:::warning
While you can increase the interactive transaction timeout limit, it’s recommended to inspect and optimize your database transactions if they take longer than 15 seconds. Long-running transactions can negatively impact performance and often signal the need for optimization. Learn more in the [troubleshooting guide](/accelerate/troubleshoot#p6004-querytimeout) and review the [warning in the Interactive Transactions section](/orm/prisma-client/queries/transactions#interactive-transactions-1) in our documentation.
:::
Expand Down
6 changes: 5 additions & 1 deletion content/300-accelerate/600-faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,8 @@ The [cache invalidate API](/accelerate/caching#on-demand-cache-invalidation) is
- **Inventory management**: In real-time applications, like inventory or booking systems, where stock levels, availability, or reservation statuses must reflect the latest information.
- **High-priority data**: For time-sensitive data, like breaking news or urgent notifications, where it’s essential for users to see the most current information right away.

Using on-demand cache invalidation in these scenarios helps keep only the necessary data refreshed, preserving system performance while ensuring accurate, up-to-date information for users.
Using on-demand cache invalidation in these scenarios helps keep only the necessary data refreshed, preserving system performance while ensuring accurate, up-to-date information for users.

## How does Accelerate count queries for billing?

Accelerate counts queries at the Prisma Client invocation level. A single Prisma query may translate into multiple SQL statements under the hood, but it will only count as one query for billing purposes. This ensures straightforward, predictable billing that reflects the Prisma Client usage rather than the complexity of the underlying SQL operations.
2 changes: 2 additions & 0 deletions content/500-platform/10-about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The [Console](https://console.prisma.io/login) enables you to manage and configu

- [Accelerate](/accelerate): Speeds up your queries with a global database cache with scalable connection pooling.
- [Pulse](/pulse): Enables you to build event-driven and real-time applications by letting you stream database change events in a type-safe way.
- [Optimize](/optimize): Provides you recommendations that can help you make your database queries faster.
- [Prisma Postgres](/orm/overview/databases/prisma-postgres): A managed PostgreSQL database that is optimized for Prisma.

## Concepts

Expand Down
1 change: 1 addition & 0 deletions content/700-optimize/300-recordings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ When a recording session ends, Optimize generates recommendations such as:
- [Overfetching](/optimize/recommendations/select-returning)
- [Using `@db.Money`](/optimize/recommendations/avoid-db-money)
- [Using `@db.VarChar(n)`](/optimize/recommendations/avoid-varchar)
- [Using `timestamp(0)` or `timestamptz(0)`](/optimize/recommendations/avoid-timestamp-timestampz-0)

:::info
Use [Prisma AI](/optimize/prisma-ai) to ask follow-up questions about a recommendation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: 'Using timestamp(0) or timestamptz(0)'
metaTitle: 'Optimize Recommendations: Avoid usage of `timestamp(0)` or `timestamptz(0)`'
metaDescription: "Learn about the recommendation provided by Optimize for using `timestamp(0)` or `timestamptz(0)` native type."
tocDepth: 3
toc: true
---

Optimize provides recommendations to help you identify and resolve performance issues caused by the use of `@db.Timestamp(0)` and `@db.Timestamptz(0)` native types in PostgreSQL.

The `@db.Timestamp(0)` and `@db.Timestamptz(0)` native types have been used within the following `User` model:

```prisma
model User {
// ...
date DateTime @db.Timestamp(0)
deletedAt DateTime @db.Timestamptz(0)
// ...
}
```

### Why this is a problem

When using a `@db.Timestamp(n)` or `@db.Timestamptz(n)` column with a precision of `0`, the database rounds the time to the nearest whole second, which can lead to unexpected results.

For example, if you insert the current time, such as `15:30:45.678`, into a column with this precision, it will round up to `15:30:46`. This behavior can cause the recorded time to appear up to half a second in the future compared to the original time, which may be surprising when precise time accuracy is critical.
4 changes: 2 additions & 2 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ const config: Config = {
[path.resolve(__dirname, 'client-plugins', 'posthog-docusaurus'),
{
apiKey: DOCUSAURUS_POST_HOG_KEY,
appUrl: DOCUSAURUS_BASE_URL,
person_profiles: "identified_only",
appUrl: 'https://proxyhog.prisma-data.net', // this is safe to have in version control
person_profiles: 'identified_only',
enableInDevelopment: false
},
],
Expand Down
94 changes: 34 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@docusaurus/types": "^3.5.2",
"prettier": "3.4.2",
"typescript": "~5.7.2",
"wrangler": "^3.95.0"
"wrangler": "^3.99.0"
},
"browserslist": {
"production": [
Expand Down

0 comments on commit 3cdf73e

Please sign in to comment.