Prisma/Planetscale issue

Hello, why can't I define an array of strings in prisma using mysql and planetscale? Edit: I understand the error message and "why" it doesn't work but I can't find a solution to the issue.
No description
6 Replies
Christoph
Christoph16mo ago
Because Planetscale uses Vitess which is based on MySQL which doesn't have arrays like PostgreSQL.
Ducky Sensei
Ducky SenseiOP16mo ago
And how would I go about to handle a field that can have multiple inputs? Would a good solution be to Type it as a JSON and then store it as: {1: "url", 2:"url2"}?
Christoph
Christoph16mo ago
Usually a bad idea. Normalize your data unless you have a reason not to.
Ducky Sensei
Ducky SenseiOP16mo ago
The problem is that I need something in the form of: model Org { ... allowedDomains: ["Domain 1", "Domain 2"] } Do I really have to make a new model and then do a relation to this Org model where I allow multiple inputs?
Christoph
Christoph16mo ago
That's the way it's usually done. Of course can use JSON or blob or w/e - but an extra table makes it easier to query the data.
Alejo
Alejo16mo ago
The other option would be to use a special separator and use a LIKE query(i.e. WHERE allowedDomains LIKE 'domain.com|%' OR allowedDomains LIKE '%|domain.com|%' allowedDomains LIKE '%|domain.com' ), but that's prone to errors and, like Christoph said, the way it is normally done is using a separate model and table
Want results from more Discord servers?
Add your server