如何插入数组?

How to upsert with arrays?

也许这是一个非常愚蠢的问题,但我应该如何在更新时将值推送到数组字段?我试图搜索它,但在他们的文档中找不到它。

这是我的架构:

model Chat {
  id                Int         @default(autoincrement()) @id
  type              Service[]
  chatId            String      @unique
}

这是我尝试用来更新数组以将项目推送到其中的代码:

const chatDb = await prisma.chat.upsert({
      where: {
        chatId: String(ctx.chat.id),
      },
      create: {
        chatId: String(ctx.chat.id),
        type: { set: ['GRAYSCALE'] },
      },
      update: {
        type: { set: ['GRAYSCALE'] },
      },
    });

我现在的使用方式是用 type 数组替换 ['GRAYSCALE'] 数组。我想将 GRAYSCALE 项推入数组,而不是替换它。

我应该如何进行?

目前无法直接upsert一个数组。您需要先获取它,添加项目然后更新。

我建议遵循 this 请求并在问题中添加一个,以便我们可以设置优先级。