# Types for your code (/docs/orm/fundamentals/types) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Name the type of a row, a query result, or a create, update, or filter argument in Prisma ORM 8, with the Prisma ORM 7 name beside each one. Location: ORM > Fundamentals > Types for your code When a function returns a user or takes a filter, you want to name that type instead of repeating the fields. This page shows the types for both, on PostgreSQL first and then on MongoDB. The types start from your contract, `src/prisma/contract.prisma`, the file where you declare your models. Run `npx prisma contract emit` after every change to it; it writes `contract.d.ts` next to the contract, with one type per model. You pass that type to the helper types on this page. They come from `@prisma/orm-postgres`, the package your app already uses. `db` in the examples is the client from `src/prisma/db.ts`, imported with `import { db } from "./prisma/db";`. The examples use this contract: ```prisma title="src/prisma/contract.prisma" model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model Post { id Int @id @default(autoincrement()) title String author User @relation(fields: [authorId], references: [id]) authorId Int } ``` ## Model types [#model-types] `contract.d.ts` exports `Models`, with one type per model, and `Contract`, the type of the whole contract, which you need for the argument types further down. Import them with a path relative to your own file; from a file in `src/`, that is: ```ts import type { Contract, Models } from "./prisma/contract.d"; ``` On PostgreSQL, a model's type name starts with the PostgreSQL schema its table is in, so a model in the default `public` schema is `Models.public_User`. A model type lists every scalar field and every relation. No query returns all of them, so do not use it as the type of a row. Pass it to `Scalars` or `Shape` instead. ## The row a query returns [#the-row-a-query-returns] `Scalars` is a row with every scalar field and no relations. It is what `first()` and `all()` return when you call neither `select()` nor `include()`: ```ts import type { Scalars } from "@prisma/orm-postgres/family-contract/types"; type User = Scalars; async function getUser(id: number): Promise { return db.orm.public.User.where({ id }).first(); } ``` `ResultType` is the row of a query you have already written. When the query depends on an argument, put it in a function that returns the query, and take the type of what the function returns: ```ts import type { ResultType } from "@prisma/orm-postgres/components/runtime"; function userWithPosts(id: number) { return db.orm.public.User.where({ id }).include("posts"); } type UserWithPosts = ResultType>; ``` `first()` on that query returns `UserWithPosts | null`, and `all()` returns `UserWithPosts[]`. ## Choose the fields of a row [#choose-the-fields-of-a-row] `Shape` describes a row with the fields and relations you choose, so you can declare what a function returns before you write the query. A user with all of their posts is: ```ts import type { Shape } from "@prisma/orm-postgres/family-contract/types"; type UserWithPosts = Shape; async function getUserWithPosts(id: number): Promise { return db.orm.public.User.where({ id }).include("posts").first(); } ``` The query's result fits the type as it is, so the function returns it directly. The spec, the second argument, works like this: * `"+"` lists what to keep, as a union such as `"id" | "posts"`. If it names any scalar field, you get only the scalar fields it names, plus any relations it names. If it names only relations, you get every scalar field plus those relations. A relation in `"+"` comes with all of its scalar fields and none of its own relations. * `"-"` lists scalar fields to leave out. A relation cannot be listed, because a row has no relations unless you ask for them. * You cannot name scalar fields in both `"+"` and `"-"` of the same spec. * Any other key is a relation, which the key alone adds to the row, and its value is a spec for that relation's rows, such as `posts: { "+": "id" | "title" }`. * With no `"+"` and no `"-"`, you get every scalar field, so `Shape` is the same as `Scalars`. Breaking one of these rules, or naming a field the model does not have, is a TypeScript error that names that key. To add a field no query returns, such as a computed count, combine types: `Shape & { postCount: number }`. Leaving a field out of a type does not remove it from the data. TypeScript accepts a row that still has `email` where the type has none, so a function that must not send `email` to a client selects only the fields it needs: ```ts type PublicUser = Shape; async function getPublicUser(id: number): Promise { return db.orm.public.User.where({ id }).select("id", "name").first(); } ``` ## The arguments you pass in [#the-arguments-you-pass-in] The argument types come from `@prisma/orm-postgres/orm-client`. Each takes `Contract` first and the model name, and `ShorthandWhereFilter` and `ModelAccessor` also take the PostgreSQL schema, in a different position in each, as the examples show: ```ts import type { CreateInput, ScalarUpdateInput, ShorthandWhereFilter, UniqueConstraintCriterion, } from "@prisma/orm-postgres/orm-client"; function createUser(data: CreateInput) { return db.orm.public.User.create(data); } function updateUser(id: number, data: ScalarUpdateInput) { return db.orm.public.User.where({ id }).update(data); } function findUsers(filter: ShorthandWhereFilter) { return db.orm.public.User.where(filter).all(); } function findByKey(key: UniqueConstraintCriterion) { return db.orm.public.User.whereUnique(key).first(); } ``` * `CreateInput` is what `create()` takes. A field with a default is optional, and a relation field can create related rows, as in `posts: (p) => p.create([{ title: "Hello" }])`, which replaces Prisma ORM 7's `posts: { create: [...] }`. `create()` returns the new row as `Scalars`. * `ScalarUpdateInput` is the scalar fields `update()` takes, each one optional. It does not include relation changes such as `connect`, and no exported type does yet, so pass relation changes in a separate argument of your function and write them where you call `update()`. * `ShorthandWhereFilter` is a filter written as an object, such as `{ name: "Ada" }`, which matches rows whose fields equal those values. Its second argument is the PostgreSQL schema of the model. * `UniqueConstraintCriterion` is what `whereUnique()` takes: the `@id`, a `@unique` field, or all the fields of a `@@unique`, such as `{ email: "ada@example.com" }`. `first()` then returns that row or `null`. A filter that uses operators, such as `ilike` or `or`, or that filters on a relation, is a function instead of an object. The function takes a `ModelAccessor` and returns a `Condition`: ```ts import { or, type Condition, type ModelAccessor } from "@prisma/orm-postgres/orm-client"; type UserFields = ModelAccessor; function findUsersWhere(filter: (user: UserFields) => Condition) { return db.orm.public.User.where(filter).all(); } await findUsersWhere((user) => user.email.ilike("%@example.com")); await findUsersWhere((user) => or(user.name.eq("Ada"), user.name.eq("Grace"))); await findUsersWhere((user) => user.posts.some((post) => post.title.eq("Hello"))); ``` [Reading data](https://www.prisma.io/docs/orm/fundamentals/reading-data) lists the operators. ## Coming from Prisma ORM 7 [#coming-from-prisma-orm-7] Prisma ORM 8 has no `Prisma` namespace; each type above replaces one from Prisma ORM 7: | Prisma ORM 7 | Prisma ORM 8 | | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | | `User` from your generated client | `Scalars` | | `Prisma.UserGetPayload<{ include: { posts: true } }>` | `Shape` | | `Prisma.UserGetPayload<{ select: { id: true; posts: { select: { title: true } } } }>` | `Shape` | | `Awaited>` | still works; `ResultType>` names the row of a function that returns a query | | `Prisma.UserCreateInput` | `CreateInput` | | `Prisma.UserUpdateInput` | `ScalarUpdateInput`, for scalar fields | | `Prisma.UserWhereInput` | `ShorthandWhereFilter` for equality, a function of `ModelAccessor` for operators and relation filters | | `Prisma.UserWhereUniqueInput` | `UniqueConstraintCriterion` | The difference to notice first is in the plain row. In Prisma ORM 7, the `User` type had the scalar fields only. In Prisma ORM 8, `Models.public_User` has every relation too, so the plain row is `Scalars`. ## MongoDB [#mongodb] On MongoDB, where the contract has no `namespace` blocks, a model is `Models.unbound_User`, and the types come from `@prisma/orm-mongo`: | Type | Import from | | ---------------------------------------------------------------- | -------------------------------------- | | `Scalars`, `Shape` | `@prisma/orm-mongo/family-contract` | | `ResultType` | `@prisma/orm-mongo/components/runtime` | | `CreateInput`, `UpdateInput` | `@prisma/orm-mongo/orm` | | `MongoWhereFilter`, the filter for `where()` | `@prisma/orm-mongo/orm` | ## Next steps [#next-steps] * [Model and result types](https://www.prisma.io/docs/orm/reference/orm-client#model-and-result-types) in the client reference. * [Reading data](https://www.prisma.io/docs/orm/fundamentals/reading-data) shows `select()`, `include()`, and `where()`, whose results these types describe. ## Related pages - [`Advanced queries`](https://www.prisma.io/docs/orm/fundamentals/advanced-queries): Use the SQL query builder on PostgreSQL and the pipeline builder on MongoDB for queries the ORM API can't express. - [`Reading data`](https://www.prisma.io/docs/orm/fundamentals/reading-data): Fetch one record or many with Prisma ORM, then filter, select, sort, paginate, and iterate the results. - [`Relations and joins`](https://www.prisma.io/docs/orm/fundamentals/relations-and-joins): Read related records in one query with .include(), and understand how one-to-one, one-to-many, and many-to-many relationships work. - [`Transactions`](https://www.prisma.io/docs/orm/fundamentals/transactions): Run several writes so they all succeed or all fail together with db.transaction(). - [`Writing data`](https://www.prisma.io/docs/orm/fundamentals/writing-data): Create, update, delete, and upsert records with Prisma ORM, one at a time or in bulk.