Đức Sine
Đức Sine

Reputation: 3

prisma query postgresql into nestJs

I have a problem as following: schema:

model company {
    id           Int      @id @default(autoincrement())
    name         String?
    services company_service[]
   ...
}

model company_service {
    companyId Int @map("company_id")
    serviceId Int @map("service_id")

    company company? @relation(fields: [companyId], references: [id])
    service service? @relation(fields: [serviceId], references: [id])
    @@id([companyId, serviceId])
}

model service {
    id    Int     @id @default(autoincrement())
    name  String?
    
    companies company_service[]
    jobs      job[]
}


model job {
    id              Int       @id @default(autoincrement())
    
    customerId      Int?      @map("customer_id")
    serviceId       Int?      @map("service_id")
  
    addressId       Int?      @map("address_id")
   
    status          Int?      @default(1) // 1: Available, 2: In Progress, 3:Cancel ,4: Completed,
    

    customer customer?     @relation(fields: [customerId], references: [id])
   
    service  service?      @relation(fields: [serviceId], references: [id])
  
}.

I need to execute the query:

SELECT company_id, count(j.status) as numberOfWorkComplete
FROM company_service sv, job j
WHERE sv.service_id = j.service_id and j.status = 4 
GROUP BY company_id 

I have the result of the above query but is there any way i can still get that result without having to write sql? thanks

Upvotes: 0

Views: 340

Answers (1)

Ryan
Ryan

Reputation: 6327

Currently a raw query is the only way to do this. We have a request for the same here so it would be great if you could add a 👍 to this so that we can look at the priority.

Upvotes: 1

Related Questions