Prisma sqlite列表

发布于 2025-01-28 17:19:57 字数 443 浏览 0 评论 0 原文

我正在尝试使用 String [] 将列表添加到模型中,但是它给了我这个错误:

Field "stats" in model "Player" can't be a list.
The current connector does not support lists of primitive types.

代码:


generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./db.db"
}

model Player {
  id String @id @default(cuid())
  stats String[]
}

有办法做到这一点吗?

I'm trying to add a List to a model using String[] but it it gives me this error:

Field "stats" in model "Player" can't be a list.
The current connector does not support lists of primitive types.

Code:


generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./db.db"
}

model Player {
  id String @id @default(cuid())
  stats String[]
}

Is there a way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素罗衫 2025-02-04 17:19:57

标量列表(数组)仅在您的数据库本地支持时才支持。因此,仅在使用PostgreSQL或CockroachdB时支持标量列表(因为MySQL和 sqlite不本地支持标量列表)。

另外,您可以尝试使用字符串类型列,然后在写入数据库之前将数组转换为带有commas的字符串。

但是,更新将需要更多的工作,因为您不能使用 unsot prisma中的方法,并且如果您的更新取决于当前状态,则可能必须使用多个查询(例如1st查询以获取当前数组,第二查询以更新数组)。

Scalar lists (arrays) are only supported in the data model if your database natively supports them. Currently, scalar lists are therefore only supported when using PostgreSQL or CockroachDB (since MySQL and SQLite don't natively support scalar lists).

https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#-modifier

Alternatively, you can try using a string type column and convert your array into string with separator like commas before writing into database.

However, update will require more work as you cannot use unset or push method from prisma, and likely have to use multiple queries if your update depends on the current state (e.g. 1st query to get the current array, 2nd query to update array).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文