标量列表
示例使用以下 prisma 模式
model Post {
id String @id @default(cuid())
title String
tags String[]
}
通过数组字段查询记录
注意:这仅适用于 postgres。
post, err := client.Post.FindFirst(
// whether the list contains a single field
db.Post.Tags.Has("coffee"),
// or
// whether the tag contains coffee _and_ juice
db.Post.Tags.HasEvery([]string{"coffee", "juice"}),
// or
// whether the tag contains coffee or tea
db.Post.Tags.HasSome([]string{"coffee", "tea"}),
// or
db.Post.Tags.IsEmpty(false),
).Exec(ctx)
写入数组字段
设置字段,无论之前的值如何
post, err := client.Post.FindUnique(
db.Post.ID.Equals("123"),
).Update(
db.Post.Tags.Set([]string{"a", "b", "c"}),
).Exec(ctx)
将项目添加到现有列表中(仅限 postgres)
post, err := client.Post.FindUnique(
db.Post.ID.Equals("123"),
).Update(
db.Post.Tags.Push([]string{"a", "b"}),
).Exec(ctx)
备注
标量列表中的 NULL 值 可能需要额外考虑 (在新标签页中打开).