How to add item to array in prisma database at frontend?

Hello, lets say I have user and this user have coins. How can I then inside a React component add coins to this array? And then displaying them on different page? For example:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
coins Coin[]
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
coins Coin[]
}
model Coin {
id String @id @default(cuid())
name String
rank Int?
User User? @relation(fields: [userId], references: [id])
userId String?
}
model Coin {
id String @id @default(cuid())
name String
rank Int?
User User? @relation(fields: [userId], references: [id])
userId String?
}
And then let's say in frontend I want a button that adds item to this Coin array.
2 Replies
Neto
Neto3y ago
you need a way to communicate from the react component with the api/database be doing a api call (not secure for the most part) or with something like trpc/graphql/etc
noctate
noctateOP3y ago
oh I see, since I'm already using trpc in my project I should dig into docs to see how it works with prisma
Want results from more Discord servers?
Add your server