Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jharrell/clean-up-help
Browse files Browse the repository at this point in the history
  • Loading branch information
jharrell committed Jan 1, 2025
2 parents 0f641f1 + d21a366 commit 79e3e7a
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 87 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
},
},
},
},
})
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---

title: 'Using the Nuxt Prisma Module'
metaTitle: 'Add Prisma ORM Easily to Your Nuxt Apps'
metaDescription: 'Learn how to easily add Prisma ORM to your Nuxt apps, use its features, and understand its limitations.'

---

The Nuxt Prisma module simplifies the integration of Prisma ORM into your Nuxt applications.
Expand Down Expand Up @@ -187,17 +185,6 @@ If you're using [Nuxt server components](https://nuxt.com/docs/guide/directory-s
</template>
```

#### Using the auto-imported Prisma Client instance in your API route

You can use the auto-imported Prisma Client instance, prisma, in your Nuxt API route as follows:
```typescript
export default defineEventHandler(async (event) => {
return {
user: await prisma.user.findFirst(),
};
});
```

### Option B: `lib/prisma.ts`

After running through the initial setup prompts, this module creates the `lib/prisma.ts` file which contains a global instance of Prisma Client.
Expand Down Expand Up @@ -299,6 +286,9 @@ export default defineNuxtConfig({
| **formatSchema** | `boolean` | true | Whether to [format](/orm/reference/prisma-cli-reference#format) the [Prisma Schema](/orm/prisma-schema) file. |
| **installStudio** | `boolean` | true | Whether to install and start [Prisma Studio](https://www.prisma.io/studio) in the Nuxt Devtools. |
| **autoSetupPrisma** | `boolean` | false | Whether to skip all prompts during setup. This option is useful for automating Prisma setup in scripts or CI/CD pipelines. |
| **skipPrompts** | `false` | false | Skips all prompts |
| **prismaRoot** | `string` | false | Required when using [Nuxt layers](https://nuxt.com/docs/getting-started/layers). For example, if you have a Nuxt layer called `database`, the `prismaRoot` would be `./database` in the base nuxt config. This refers to the folder where Prisma will be initialized or checked. |
| **prismaSchemaPath** | `string` | `undefined` | Required when using [Nuxt layers](https://nuxt.com/docs/getting-started/layers). For example, if you have a Nuxt layer called `database`, the `prismaSchemaPath` would be `./database/prisma/schema.prisma` in the base nuxt config. |

## Limitations

Expand Down Expand Up @@ -355,4 +345,10 @@ export default defineNuxtConfig({
})
```

This configuration ensures that the module specifier is correctly mapped to the appropriate file.
This configuration ensures that the module specifier is correctly mapped to the appropriate file.

### Limitations in package manager support

The module is designed to work with popular package managers, including npm, Yarn, and pnpm. However, as of `v0.2`, it is not fully compatible with Bun due to an issue causing an indefinite installation loop.

Additionally, this package has not been tested with Deno and is therefore not officially **supported.**
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
7 changes: 7 additions & 0 deletions content/300-accelerate/650-troubleshoot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ This error can happen when the wrong credentials are provided to Prisma Accelera

**Suggested solution:** Verify the correctness of your database's username, password, and name in the connection string provided to Prisma Accelerate. Ensure that these credentials match those required by your database. Testing the connection using a direct database GUI tool can also help in confirming if the provided credentials are correct.

#### Database taking too long to respond

If the database is taking too long to respond to the connection request, Prisma Accelerate may timeout and throw this error. This could happen if the database is not active or is waking up from sleep mode.

**Suggested solution:** Verify that the database is active and reachable. If the database is in sleep mode, try to wake it up by sending a request to it using a direct database GUI tool or wake it up using the database's management console.


## Other errors

### Error with MySQL (Aiven): "We were unable to process your request. Please refresh and try again."
Expand Down
12 changes: 12 additions & 0 deletions content/400-pulse/400-api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ _With_ having set the `REPLICA IDENDITY` to `FULL`:
}
```

:::note

To enable `REPLICA IDENTITY` with the `FULL` setting, you must configure it on a per-table basis, as it is not enabled by default. This requires executing an SQL query against your database. [Learn more here.](/pulse/database-setup/general-database-instructions#replica-identity)

:::

## `PulseDeleteEvent<User>`

### Type
Expand Down Expand Up @@ -398,3 +404,9 @@ _With_ having set the `REPLICA IDENDITY` to `FULL`:
id: '0/2A5A398'
}
```

:::note

To enable `REPLICA IDENTITY` with the `FULL` setting, you must configure it on a per-table basis, as it is not enabled by default. This requires executing an SQL query against your database. [Learn more here.](/pulse/database-setup/general-database-instructions#replica-identity)

:::
3 changes: 2 additions & 1 deletion content/500-platform/50-support.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Dedicated contact person.

## Deleting your PDP account

If you want to delete your PDP account, **email us at <a href="mailto:[email protected]">[email protected]</a>**.
If you want to delete your PDP account, **email us at <a href="mailto:[email protected]">[email protected]</a>** specifying the email id or GitHub handle with which you signed up.

To ensure that you're not accidentally disabling any infrastructure powering one of your applications, we require that you **disable Accelerate and Pulse in _all_ environments of _all_ your projects** that live in the account to be deleted.
Additionally there should be no active subscriptions in the account to be deleted. Please cancel any active subscriptions before requesting account deletion.
1 change: 1 addition & 0 deletions content/700-optimize/300-recordings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ When a recording session ends, Optimize generates recommendations such as:
- [Repeated query](/optimize/recommendations/repeated-query)
- [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
Expand Down
23 changes: 23 additions & 0 deletions content/700-optimize/400-recommendations/700-avoid-varchar.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: 'Using @db.VarChar(n)'
metaTitle: 'Optimize Recommendations: Avoid usage of `@db.VarChar(n)`'
metaDescription: "Learn about the recommendation provided by Optimize for using `@db.VarChar(n)` native type."
tocDepth: 3
toc: true
---

Optimize provides recommendations to help you identify and resolve performance issues caused by the use of `@db.VarChar(n)` type in PostgreSQL.

The `@db.VarChar(n)` native type has been used within the `Item` model on the name field:

```prisma
model Item {
// ...
name String @db.VarChar(1)
// ...
}
```

### Why this is a problem

The `@db.VarChar(n)` type restricts content to a maximum length of `n`, which can cause unexpected issues in production if not properly managed by the application. In PostgreSQL, `varchar(n)` performs the same as `text`, and no additional optimizations are provided for `varchar(n)`, making the choice between them more about convention than performance.
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
Loading

0 comments on commit 79e3e7a

Please sign in to comment.