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.
final user = await client.user.findUnique(
where: UserWhereUniqueInput(id: 'ck2l9xqjy0000yjzv6q9q4k5i'),
);
Arguments
Argument | Example Type (User ) | Required | Description |
---|---|---|---|
where | UserWhereUniqueInput | Yes | Wraps all unique identifier |
select | UserSelect | No | Select fields to fetch |
include | UserInclude | No | Include 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.
final user = await client.user.findFirst(
where: UserWhereInput(...),
);
Arguments
Argument | Example Type (User ) | Required | Description |
---|---|---|---|
where | UserWhereInput | No | Specifies which properties to include on the returned object. |
select | UserSelect | No | Select fields to fetch |
include | UserInclude | No | Include relational fields |
take | int | No | Take the first n records |
skip | int | No | Skip the first n records |
orderBy | Iterable of UserOrderByWithRelationInput or UserOrderByWithRelationInput | No | Order records by one or more properties |
cursor | UserWhereUniqueInput | No | Cursor based pagination |
`distinct | UserScalar or Iterable of UserScalar | No | Select 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.
final users = await client.user.findMany(
where: UserWhereInput(...),
);
Arguments
Argument | Example Type (User ) | Required | Description |
---|---|---|---|
where | UserWhereInput | No | Specifies which properties to include on the returned object. |
select | UserSelect | No | Select fields to fetch |
include | UserInclude | No | Include relational fields |
take | int | No | Take the first n records |
skip | int | No | Skip the first n records |
orderBy | Iterable of UserOrderByWithRelationInput or UserOrderByWithRelationInput | No | Order records by one or more properties |
cursor | UserWhereUniqueInput | No | Cursor based pagination |
`distinct | UserScalar or Iterable of UserScalar | No | Select distinct records |
create()
The create()
method is used to create new records.
final user = await client.user.create(
...
);
Arguments
Argument | Example Type (User ) | Required | Description |
---|---|---|---|
data | PrismaUnion of UserCreateInput or UserUncheckedCreateInput | Yes | Data to create |
select | UserSelect | No | Select fields to fetch |
include | UserInclude | No | Include relational fields |
update()
The update()
method is used to update existing records.
final user = await client.user.update(
where: UserWhereUniqueInput(id: 'ck2l9xqjy0000yjzv6q9q4k5i'),
data: UserUpdateInput(...),
);
Arguments
Argument | Example Type (User ) | Required | Description |
---|---|---|---|
data | PrismaUnion of UserCreateInput or UserUncheckedCreateInput | Yes | Data to create |
select | UserSelect | No | Select fields to fetch |
include | UserInclude | No | Include relational fields |
where | UserWhereUniqueInput | Yes | Where condition |
upsert()
The upsert()
method is used to update existing records or create new records.
Arguments
Argument | Example Type (User ) | Required | Description |
---|---|---|---|
where | UserWhereUniqueInput | Yes | Where condition |
create | PrismaUnion of UserCreateInput or UserUncheckedCreateInput | Yes | Data to create |
update | PrismaUnion of UserUpdateInput or UserUncheckedUpdateInput | Yes | Data to update |
select | UserSelect | No | Select fields |
include | UserInclude | No | Include fields |
delete()
The delete()
method is used to delete existing records.
final user = await client.user.delete(
where: UserWhereUniqueInput(id: 'ck2l9xqjy0000yjzv6q9q4k5i'),
);
Arguments
Argument | Example Type (User ) | Required |
---|---|---|
where | UserWhereUniqueInput | Yes |
select | UserSelect | No |
include | UserInclude | No |
createMany()
The createMany()
method is used to create multiple records.
Arguments
Argument | Example Type (User ) | Required |
---|---|---|
data | PrismaUnion of UserCreateManyInput or Iterable of UserCreateManyInput | Yes |
skipDuplicates | bool | No |
updateMany()
The updateMany()
method is used to update multiple records.
Arguments
Argument | Example Type (User ) | Required |
---|---|---|
data | PrismaUnion of UserUpdateManyMutationInput or UserUncheckedUpdateManyInput | Yes |
where | UserWhereInput | No |
deleteMany()
The deleteMany()
method is used to delete multiple records.
Arguments
Argument | Example Type (User ) | Required |
---|---|---|
where | UserWhereInput | No |
aggregate()
The aggregate()
method is used to aggregate multiple records. See Queries → Aggregate for more information.
Arguments
Argument | Example Type (User ) | Required |
---|---|---|
`where | UserWhereInput | No |
orderBy | PrismaUnion of Iterable ofUserOrderByWithRelationInput orUserOrderByWithRelationInput | No |
cursor | UserWhereUniqueInput | No |
take | int | No |
skip | int | No |
select | AggregateUserSelect | No |
groupBy()
The groupBy()
method is used to group multiple records based on given criteria. See Queries → Group By for more information.
Arguments
Argument | Example Type (User ) | Required |
---|---|---|
where | UserWhereInput | No |
orderBy | PrismaUnion of Iterable of UserOrderByWithAggregationInput or UserOrderByWithAggregationInput | No |
by | PrismaUnion of Iterable of UserScalar or UserScalar | Yes |
having | UserScalarWhereWithAggregatesInput | No |
take | int | No |
skip | int | No |
select | UserGroupByOutputTypeSelect | No |