Questions tagged [prisma2]

For questions about Version 2 of the Prisma ORM

232 questions
4
votes
1 answer

Changing Name & Location of the Prisma Folder in Prisma 2

I would like to change the name and location of the prisma folder. Currently it called prisma and it sits on the root folder of my nextjs project. I'd like to name it db and have it within the src folder. Is that possible? If so, how?
Moshe
  • 6,011
  • 16
  • 60
  • 112
4
votes
1 answer

Is it possible to access metadata about the prisma model?

Let's say I have a model in my schema.prisma file: model Post { id Int @id @default(autoincrement()) author User @relation(fields: [authorId], references: [id]) authorId Int } Having a variable called model in my server…
daniel grieb
  • 155
  • 7
4
votes
1 answer

Nested writes in Prisma

My schema looks like this: model User { id Int @default(autoincrement()) @id createdAt DateTime @default(now()) email String @unique role String @default("user") sessions Session[] …
Kayote
  • 14,579
  • 25
  • 85
  • 144
4
votes
1 answer

Prisma 2: Unknown arg `where` in select.count.where for type undefined

I'm unable to apply a where clause to a simple count() query on a model. If I remove the where clause it works just fine and returns the number of rows in that table. Good: let result = await prisma.articles.count() Bad: let result = await…
Dave Novelli
  • 2,086
  • 4
  • 32
  • 42
3
votes
2 answers

Find users that follow each other on a Prisma self-relation

Given a user id, I want to find the followers that the user follows (i.e. follow each other) My Prisma model looks like the following: model User { id Int @id @default(autoincrement()) name String? followedBy Follows[]…
G.G.
  • 634
  • 1
  • 5
  • 10
3
votes
1 answer

Prisma 2 - Unkown arg 'where' in select.fruit.where for type UserFruit. Did you mean 'select'? Available args

Trying to query in prisma and filter results from a related object but get the error: Unknown arg 'where' in select.fruit.where for type UserFruit. Did you mean 'select'? Available args fruit{} async findShops(req) { const userId =…
TEZZ
  • 179
  • 1
  • 15
3
votes
1 answer

Prisma client not marking property as null

I am using Prisma version 3.8.1. Prisma client does not mark the User.oauthData property as nullable in TS. Can someone help? Prisma schema and generated SQL files below: // This is your Prisma schema file, // learn more about it in the docs:…
Raj Chaudhary
  • 1,444
  • 3
  • 16
  • 31
3
votes
1 answer

Prisma failed queries don't return proper errors

In my Prisma/express backend, I have this schema: schema.prisma : model user { id Int @id @default(autoincrement()) name String last_name String role role @relation(fields: [role_id],…
Gustavo Farias
  • 393
  • 5
  • 15
3
votes
2 answers

count self relation on Prisma error: table name specified more than once

I am trying to count a self relation (followers) in Prisma2 (using PostgreSQL) Model: model User { id String @id @default(cuid()) following User[] @relation(name: "UserFollows") followers User[] @relation(name:…
G.G.
  • 634
  • 1
  • 5
  • 10
3
votes
1 answer

Why does deleteMany use 2 queries?

I noticed that deleteMany uses two queries when I specify a where. It first selects the primary keys of the rows to delete, and then removes them with a DELETE FROM WHERE id IN (...) query. What is the use of this? Instead of the WHERE id IN (...)…
Tim
  • 231
  • 1
  • 3
  • 6
3
votes
1 answer

How do I use "AND" operator with multiple query parameters in nested relation when querying in Prisma?

Its my first time trying prisma and am stuck. So I have "products" and "filters" model. I want the following query to work. The idea is, I want to fetch the products with dynamic matching query params (name and value). The product query parameters…
Manish Karki
  • 141
  • 1
  • 1
  • 6
3
votes
0 answers

How can I sort items by custom value in Prisma? (trying to implement "sort by hot" like on Hacker News or Reddit)

I'm trying to implement "sort by hot" similar to what HackerNews/Reddit do, as described here. I want to calculate the rank of a post like so: const age = new Date() - createdAt const gravity = 1.8 const rankScore = (score - 1) / (age + 2) **…
lumenwrites
  • 1,287
  • 4
  • 18
  • 35
3
votes
3 answers

Exclude user's password from query with Prisma 2

Recently I started working on a new project to learn some new technologies (Prisma 2, REST api with Express, etc.). Tho, I faced a problem. My app has a user authentication system and the user model has a password column. So, when the client…
3
votes
3 answers

How to pass an array as args to Nexus? How to create multiple objects from this array using Prisma?

I'm trying to learn to use Prisma and Nexus together. I'm hoping that someone more experienced can help me out. I want to create a post with several images attached to it. My Prisma models look like this: model Post { id String @id…
lumenwrites
  • 1,287
  • 4
  • 18
  • 35
3
votes
1 answer

Prisma2, groupBy Date

I need to group fields by date, I use Prisma 2, for example, filter all register in month, but I don't know how to do it in the case of a date Eu preciso agrupar os campos com um intervalo de data, por exemplo todos os registros dentro de um mês! an…
1 2
3
15 16