Skip to content

Commit

Permalink
improve raw docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Feb 14, 2020
1 parent 8d66d99 commit 15c4d49
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/prisma-client-js/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ const result = await prisma.raw`SELECT * FROM User WHERE id = ${userId};`
The `raw` function has the following function signature:

```ts
raw<T = any>(query: string | TemplateStringsArray): Promise<T[]>;
raw<T = any>(query: string | TemplateStringsArray): Promise<T>;
```
The return type of `raw` is a `Promise` for an array of the generic [generic](https://www.typescriptlang.org/docs/handbook/generics.html) type parameter `T`. This means you can type the result manually by providing `T` when you invoke `raw`. If you don't provide any type, the return type of `raw` defaults to `any[]`.
The return type of `raw` is a `Promise` for the [generic](https://www.typescriptlang.org/docs/handbook/generics.html) type parameter `T`. This means you can type the result manually by providing `T` when you invoke `raw`. If you don't provide any type, the return type of `raw` defaults to `any`.
```ts
// import the generated `User` type from the `@prisma/client` module
import { User } from '@prisma/client'

const result = await prisma.raw<User>('SELECT * FROM User;')
const result = await prisma.raw<User[]>('SELECT * FROM User;')
// result is of type: `User[]`
```

Expand All @@ -237,6 +237,8 @@ Now, `result` is strongly typed to the generated `User` type (or rather an array

If you're selecting only specific fields of the model or want to include relations, read the documentation about [leveraging Prisma Client's generated types](./generated-types.md) if you want to ensure that the query results are properly typed.

Note that calls to `SELECT` always return arrays of type `T`, but other SQL operations (like `INSERT` or `UPDATE`) might return single objects.

## Scalar lists

Prisma Client JS provides a dedicated API for (re)setting _scalar lists_ using a `set` field inside the `data` argument when creating or updating a [Prisma model](../data-modeling.md#models), for example:
Expand Down

0 comments on commit 15c4d49

Please sign in to comment.