Skip to content

Model Delegate

Model Delegate is the action delegate used to access tables/views, they are automatically generated by Prisma Client.

Typically, they use camelCase notation starting with lowercase on PrismaClient, such as client.user.

In the prisma.dart file, the generated Delegate uses the camelCase notation of the <Model>Delegate name, such as UserDelegate.

findUnique()

The findUnique() method is used to find a single record based on a unique identifier.

dart
final user = await client.user.findUnique(
    where: UserWhereUniqueInput(id: 'ck2l9xqjy0000yjzv6q9q4k5i'),
);

Arguments

ArgumentExample Type (User)RequiredDescription
whereUserWhereUniqueInputYesWraps all unique identifier
selectUserSelectNoSelect fields to fetch
includeUserIncludeNoInclude relational fields

findUniqueOrThrow()

findUniqueOrThrow() is the same as findUnique(), but throws an exception error if the record is not found.

findFirst()

The findFirst() method is used to find the first record based on given conditions.

dart
final user = await client.user.findFirst(
    where: UserWhereInput(...),
);

Arguments

ArgumentExample Type (User)RequiredDescription
whereUserWhereInputNoSpecifies which properties to include on the returned object.
selectUserSelectNoSelect fields to fetch
includeUserIncludeNoInclude relational fields
takeintNoTake the first n records
skipintNoSkip the first n records
orderByIterable of UserOrderByWithRelationInput or UserOrderByWithRelationInputNoOrder records by one or more properties
cursorUserWhereUniqueInputNoCursor based pagination
`distinctUserScalar or Iterable of UserScalarNoSelect distinct records

findFirstOrThrow()

findFirstOrThrow() is the same as findFirst(), but throws an exception error if the record is not found.

findMany()

The findMany() method is used to find multiple records based on given conditions.

dart
final users = await client.user.findMany(
    where: UserWhereInput(...),
);

Arguments

ArgumentExample Type (User)RequiredDescription
whereUserWhereInputNoSpecifies which properties to include on the returned object.
selectUserSelectNoSelect fields to fetch
includeUserIncludeNoInclude relational fields
takeintNoTake the first n records
skipintNoSkip the first n records
orderByIterable of UserOrderByWithRelationInput or UserOrderByWithRelationInputNoOrder records by one or more properties
cursorUserWhereUniqueInputNoCursor based pagination
`distinctUserScalar or Iterable of UserScalarNoSelect distinct records

create()

The create() method is used to create new records.

dart
final user = await client.user.create(
    ...
);

Arguments

ArgumentExample Type (User)RequiredDescription
dataPrismaUnion of UserCreateInput or UserUncheckedCreateInputYesData to create
selectUserSelectNoSelect fields to fetch
includeUserIncludeNoInclude relational fields

update()

The update() method is used to update existing records.

dart
final user = await client.user.update(
    where: UserWhereUniqueInput(id: 'ck2l9xqjy0000yjzv6q9q4k5i'),
    data: UserUpdateInput(...),
);

Arguments

ArgumentExample Type (User)RequiredDescription
dataPrismaUnion of UserCreateInput or UserUncheckedCreateInputYesData to create
selectUserSelectNoSelect fields to fetch
includeUserIncludeNoInclude relational fields
whereUserWhereUniqueInputYesWhere condition

upsert()

The upsert() method is used to update existing records or create new records.

Arguments

ArgumentExample Type (User)RequiredDescription
whereUserWhereUniqueInputYesWhere condition
createPrismaUnion of UserCreateInput or UserUncheckedCreateInputYesData to create
updatePrismaUnion of UserUpdateInput or UserUncheckedUpdateInputYesData to update
selectUserSelectNoSelect fields
includeUserIncludeNoInclude fields

delete()

The delete() method is used to delete existing records.

dart
final user = await client.user.delete(
    where: UserWhereUniqueInput(id: 'ck2l9xqjy0000yjzv6q9q4k5i'),
);

Arguments

ArgumentExample Type (User)Required
whereUserWhereUniqueInputYes
selectUserSelectNo
includeUserIncludeNo

createMany()

The createMany() method is used to create multiple records.

Arguments

ArgumentExample Type (User)Required
dataPrismaUnion of UserCreateManyInput or Iterable of UserCreateManyInputYes
skipDuplicatesboolNo

updateMany()

The updateMany() method is used to update multiple records.

Arguments

ArgumentExample Type (User)Required
dataPrismaUnion of UserUpdateManyMutationInput or UserUncheckedUpdateManyInputYes
whereUserWhereInputNo

deleteMany()

The deleteMany() method is used to delete multiple records.

Arguments

ArgumentExample Type (User)Required
whereUserWhereInputNo

aggregate()

The aggregate() method is used to aggregate multiple records. See Queries → Aggregate for more information.

Arguments

ArgumentExample Type (User)Required
`whereUserWhereInputNo
orderByPrismaUnionof Iterable ofUserOrderByWithRelationInputorUserOrderByWithRelationInputNo
cursorUserWhereUniqueInputNo
takeintNo
skipintNo
selectAggregateUserSelectNo

groupBy()

The groupBy() method is used to group multiple records based on given criteria. See Queries → Group By for more information.

Arguments

ArgumentExample Type (User)Required
whereUserWhereInputNo
orderByPrismaUnion of Iterable of UserOrderByWithAggregationInput or UserOrderByWithAggregationInputNo
byPrismaUnion of Iterable of UserScalar or UserScalarYes
havingUserScalarWhereWithAggregatesInputNo
takeintNo
skipintNo
selectUserGroupByOutputTypeSelectNo

Released under the BSD-3-Clause License