Skip to content

Commit

Permalink
resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Mar 12, 2024
2 parents 4ba52ab + 5093593 commit f0e366c
Show file tree
Hide file tree
Showing 30 changed files with 643 additions and 355 deletions.
4 changes: 2 additions & 2 deletions content/200-orm/100-prisma-schema/20-data-model/10-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ model Post {
model Comment {
id Int
// Other fields
Post Post? @relation(fields: [postId], references: [id]) // A comment can have one post
post Post? @relation(fields: [postId], references: [id]) // A comment can have one post
postId Int?
}
```
Expand All @@ -413,7 +413,7 @@ model Post {
model Comment {
id String @id @default(auto()) @map("_id") @db.Objectid
// Other fields
Post Post? @relation(fields: [postId], references: [id]) // A comment can have one post
post Post? @relation(fields: [postId], references: [id]) // A comment can have one post
postId String? @db.ObjectId
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,19 @@ Both `distinct` and `groupBy` group records by one or more unique field values.

## Count

Use [`count`](/orm/reference/prisma-client-reference#count) to count the number of records or non-`null` field values. The following example query counts all users:
### Count records

Use [`count()`](/orm/reference/prisma-client-reference#count) to count the number of records or non-`null` field values. The following example query counts all users:

```ts
const userCount = await prisma.user.count()
```

### Count relations

The ability to count relations is available in version [3.0.1](https://github.com/prisma/prisma/releases/3.0.1) and later.

<Admonition type="info">

**For versions before 3.0.1**<br />
You need to add the [preview feature](/orm/reference/preview-features/client-preview-features#enabling-a-prisma-client-preview-feature) `selectRelationCount` and then run `prisma generate`.
This feature is generally available in version [3.0.1](https://github.com/prisma/prisma/releases/3.0.1) and later. To use this feature in versions before 3.0.1 the [Preview feature](/orm/reference/preview-features/client-preview-features#enabling-a-prisma-client-preview-feature) `selectRelationCount` will need to be enabled.

</Admonition>

Expand Down Expand Up @@ -380,7 +379,7 @@ The `_count` parameter:
- Can be used inside a top-level `include` _or_ `select`
- Can be used with any query that returns records (including `delete`, `update`, and `findFirst`)
- Can return [multiple relation counts](#return-multiple-relation-counts)
- From version 4.3.0, can [filter relation counts](#filter-the-relation-count)
- Can [filter relation counts](#filter-the-relation-count) (from version 4.3.0)

#### Return a relations count with <inlineCode>include</inlineCode>

Expand Down Expand Up @@ -415,7 +414,7 @@ const usersWithCount = await prisma.user.findMany({

#### Return a relations count with `select`

The following query uses `select` to return each user's post count and no other fields:
The following query uses `select` to return each user's post count _and no other fields_:

<CodeWithResult>
<cmd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ For relational databases, Prisma Client exposes four methods that allow you to s
- `$queryRawUnsafe` to return actual records (for example, using `SELECT`) using a raw string. **Potential SQL injection risk**
- `$executeRawUnsafe` to return a count of affected rows (for example, after an `UPDATE` or `DELETE`) using a raw string. **Potential SQL injection risk**

> **Note**: All methods in the above list can only run **one** query at a time. You cannot append a second query - for example, calling any of them with `select 1; select 2;` will not work.
### <inlinecode>$queryRaw</inlinecode>

`$queryRaw` returns actual database records. For example, the following `SELECT` query returns all fields for each record in the `User` table:
Expand Down Expand Up @@ -323,8 +325,6 @@ $executeRaw<T = unknown>(query: TemplateStringsArray | Prisma.Sql, ...values: an
The `$executeRawUnsafe` method allows you to pass a raw string (or template string) to the database. Like `$executeRaw`, it does **not** return database records, but returns the number of rows affected.
> **Note**: `$executeRawUnsafe` can only run **one** query at a time. You cannot append a second query - for example, adding `DROP bobby_tables` to the end of an `ALTER`.
<Admonition type="warning">
If you use this method with user inputs (in other words, `SELECT * FROM table WHERE columnx = ${userInput}`), then you open up the possibility for SQL injection attacks. SQL injection attacks can expose your data to modification or deletion.<br /><br />
Expand Down Expand Up @@ -561,8 +561,6 @@ Prisma Client mitigates the risk of SQL injection in the following ways:
$executeRaw`...` // Tagged template
```
- `$executeRaw` can only run **one** query at a time. You cannot append a second query - for example, adding `DROP bobby_tables` to the end of an `ALTER`.
If you cannot use tagged templates, you can instead use [`$queryRawUnsafe`](/orm/prisma-client/queries/raw-database-access/raw-queries#queryrawunsafe) or [`$executeRawUnsafe`](/orm/prisma-client/queries/raw-database-access/raw-queries#executerawunsafe) but **be aware that your code may be vulnerable to SQL injection**.
#### ⚠️ String concatenation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npx prisma migrate deploy
<Admonition type="info">

This guide **does not apply for MongoDB**.<br />
Instead of `migrate deploy`, [`db push`](/orm/prisma-migrate/workflows/prototyping-your-schema) is used for [MongoDB](/orm/overview/databases/mongodb)).
Instead of `migrate deploy`, [`db push`](/orm/prisma-migrate/workflows/prototyping-your-schema) is used for [MongoDB](/orm/overview/databases/mongodb).

</Admonition>

Expand Down
9 changes: 5 additions & 4 deletions content/200-orm/500-reference/050-prisma-client-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2775,10 +2775,11 @@ A nested `createMany` query adds a new set of records to a parent record. See: [
#### Remarks

- `createMany` is available as a nested query when you `create` (`prisma.user.create(...)`) a new parent record or `update` (`prisma.user.update(...)`) an existing parent record.
- Available in the context of a has-many relation - for example, you can `prisma.user.create(...)` a user and use a nested `createMany` to create multiple posts (posts have one user).
- **Not** available in the context of a many-to-many relation - for example, you **cannot** `prisma.post.create(...)` a post and use a nested `createMany` to create categories (many posts have many categories).
- Does not support nesting additional relations - you cannot nest an additional `create` or `createMany`.
- Allows setting foreign keys directly - for example, setting the `categoryId` on a post.
- Available in the context of a one-to-many relation — for example, you can `prisma.user.create(...)` a user and use a nested `createMany` to create multiple posts (posts have one user).
- **Not** available in the context of a many-to-many relation — for example, you **cannot** `prisma.post.create(...)` a post and use a nested `createMany` to create categories (many posts have many categories).
- Does not support nesting additional relations — you cannot nest an additional `create` or `createMany`.
- Allows setting foreign keys directly — for example, setting the `categoryId` on a post.
- Nested `createMany` is not supported by SQLite.

> You can use a nested `create` _or_ a nested `createMany` to create multiple related records - [each technique pros and cons](/orm/prisma-client/queries/relation-queries#create-a-single-record-and-multiple-related-records) .

Expand Down
35 changes: 35 additions & 0 deletions content/200-orm/500-reference/250-error-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,38 @@ The engine failed to start. For example, it couldn't establish a connection to t
#### <inlinecode>P6009</inlinecode> (<inlinecode>ResponseSizeLimitExceeded</inlinecode>)

The global response size limit of Accelerate has been exceeded. You can find the limit [here](/accelerate/limitations#response-size-limit).

### Prisma Pulse

Prisma Pulse-related errors start with <inlinecode>P61xx</inlinecode>.

#### <inlinecode>P6100</inlinecode> (<inlinecode>ServerError</inlinecode>) HTTP Status <inlinecode>500</inlinecode>

An unexpected server error occurred.
This can happen due to a technical issue within the Prisma Pulse or its infrastructure.
For any incidents related to Prisma Pulse, you can refer to our status page [here](https://www.prisma-status.com/) and reach out to our support team through one of our available [channels](https://www.prisma.io/docs/platform/support) to report your issue.

#### <inlinecode>P6101</inlinecode> (<inlinecode>DatasourceError</inlinecode>) HTTP Status <inlinecode>400</inlinecode>

Reasons:

1. The datasource is not reachable by Prisma Pulse. The Console will validate the connection when enabling Pulse to reduce the likelihood of this error. However, the datasource may become unavailable after the configuration step, resulting in this error.
2. The datasource is reachable, but did not meet the requirements for Prisma Pulse. The Console will validate the configuration when enabling Pulse to reduce the likelihood of this error. However, the datasource may change after the configuration step, resulting in this error.

#### <inlinecode>P6102</inlinecode> (<inlinecode>Unauthorized</inlinecode>) HTTP Status <inlinecode>400</inlinecode>

The API key is invalid.

#### <inlinecode>P6103</inlinecode> (<inlinecode>ProjectDisabledError</inlinecode>) HTTP Status <inlinecode>400</inlinecode>

Prisma Pulse is not enabled for the configured API key.

#### <inlinecode>P6104</inlinecode> (<inlinecode>AccountHoldError</inlinecode>) HTTP Status <inlinecode>400</inlinecode>

Your Prisma Data Platform account has been blocked, potentially due to exceeding the usage limit included in your current plan. Please review the error message for further information.

If you require further assistance, please get in touch with us via one of our support [channels](https://www.prisma.io/docs/platform/support).

#### <inlinecode>P6105</inlinecode> (<inlinecode>VersionNotSupported</inlinecode>) HTTP Status <inlinecode>400</inlinecode>

The Prisma version of the project is not compatible with Prisma Pulse.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const prismaClientSingleton = () => {
}

declare global {
var prisma: undefined | ReturnType<typeof prismaClientSingleton>
var prismaGlobal: undefined | ReturnType<typeof prismaClientSingleton>
}

const prisma = globalThis.prisma ?? prismaClientSingleton()
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()

export default prisma

if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma
if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma
```

You can extend Prisma Client using a Prisma Client extension by appending the `$extends` client method when instantiating Prisma Client as follows:
Expand Down
27 changes: 21 additions & 6 deletions content/400-pulse/100-what-is-pulse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,31 @@ toc: true

<TopBlock>

[Pulse](https://www.prisma.io/data-platform/pulse) is a managed [change data capture (CDC)](https://en.wikipedia.org/wiki/Change_data_capture) service that captures change events from your database and delivers them instantly to your applications. With Pulse, you can quickly build real-time applications in a type-safe manner using [Prisma Client](/orm/prisma-client).
[Prisma Pulse](https://www.prisma.io/data-platform/pulse) is managed database-event infrastructure that captures and distributes your database events to your application. It simplifies subscribing to type-safe data changes with an extended [Prisma Client](/orm/prisma-client) to power real-time functionality.

</TopBlock>

## How Prisma Pulse works

Prisma Pulse leverages Change Data Capture (CDC) to efficiently observe and capture database changes as they occur. By monitoring the database's transaction log, Prisma Pulse identifies change events like inserts, updates, and deletes without impacting the database's performance.

The captured events are processed, evaluated, and swiftly distributed to relevant client subscriptions ensuring your applications stay synchronized with the latest database state.

This eliminates the need for complex polling or manual data synchronization, saving you development time and effort.

![What is Pulse](./images/what-is-pulse.png)

<Admonition type="warning">
## What you can build with Prisma Pulse

Pulse is currently in [Early Access](/platform/maturity-levels#early-access). Although we already have high confidence in it, the nature of an Early Access product is that significant iterations might happen at any time. Therefore, we advise against using it in a system that requires stability.<br /><br />
Prisma Pulse can power real-time functionality like chat, notifications, data broadcast, data synchronization, and more. It's ideal for ensuring data consistency in distributed systems, enhancing real-time user experiences.

We strongly recommend evaluating Pulse with a dedicated database instance that is exclusively used for Pulse and where downtime and data loss would be acceptable. Prisma assumes no responsibility for downtime or data loss.
![Prisma Pulse use-cases](./images/pulse-usecase.png)

</Admonition>
## Examples

</TopBlock>
Here are a few example projects using Prisma Pulse:

| Project | Description |
| :--------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| [pulse-starter](https://github.com/prisma/pulse-starter) | General Pulse starter project. |
| [pulse-resend-demo](https://github.com/prisma/pulse-resend-demo) | Optimize your onboarding with Pulse by triggering welcome emails via Resend for new user sign-ups. |
Loading

0 comments on commit f0e366c

Please sign in to comment.