https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • d

    David Ilizarov

    05/28/2022, 9:53 PM
    https://www.prisma.io/docs/concepts/components/prisma-client/composite-types Just read this. Can't wait for composite types to work a-la JSON columns for Postgres 🤩
    👌 1
  • e

    Ezekiel Adetoro

    05/28/2022, 9:53 PM
    I have finished my app, I have been using
    npx prisma db
    push during my development. Because I ran
    npx prisma migrate dev
    , it gives me a bunch of error like
    permission error
    . I am using
    heroku Postgres hobby
    for my database. Now I am ready to fully deploy the app to Heroku. But I don't know how to get my
    schema.prisma
    file to Heroku. I dont know how to deploy the database to Heroku Postgres hobby to communicate with my app. What I found online and on Youtube were about #prisma1 nothing about #prisma2. Any help on how to go about this? . Should I deploy this app like a normal NodeJs app to Heroku?
    n
    • 2
    • 2
  • h

    Hussam Khatib

    05/29/2022, 10:56 AM
    Hi prisma team, I wanted to ask about the onDelete cascasde feature in mysql. whenever I am calling a
    prisma.*.delete({...})
    And view the data in prisma stdudio , I am getting this error
    inconsistent query result field * is required to return data get null instead.
    I even added the the onDelete: cascade in the relation.
    Note: Deletion behaviors for relations are not yet supported in the Prisma schema so you don't see them anywhere. The behavior will still be enforced by the database though since that's where you configured it.
    Is the reason why it is happening ?
    🙌 1
    n
    • 2
    • 3
  • b

    Berian Chaiwa

    05/29/2022, 2:53 PM
    Hello here. I am wondering how this works. In the schema I have the following definitions:
    Copy code
    created_at       DateTime @default(now()) @db.Timestamptz()
    last_modified_at DateTime @updatedAt @db.Timestamptz()
    My assumption is that both
    created_at
    and
    last_modified_at
    will default to
    now()
    and when I check the
    generated types
    for
    CreateInput
    , for both, they look as below:
    Copy code
    created_at?: Date | string
    last_modified_at?: Date | string
    But
    Prisma Studio
    tells me something different: It defaults
    last_modified_at
    to `now()`'s timestamp as expected and requires me to enter the value for
    created_at
    ! Why isn't it defaulting
    created_at
    to
    now()
    ?
    n
    • 2
    • 5
  • a

    Arnav Gosain

    05/29/2022, 3:16 PM
    Hey everyone, I have a use case I’m building a newsletter reader with prisma + sqlite as the db setup. For a particular user, I want to get the newsletters list ordered by which newsletter has the latest issue (i.e if Newsletter A has a more recent issue than Newsletter B then Newsletter A should be first in order) Following is a rough representation of my schema:
    Copy code
    model Newsletter {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
    
      name        String
      issues Issue[]
    
      User   User? @relation(fields: [userId], references: [id])
      userId Int?
    }
    
    model Issue {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
    
      subject String
      content String
    
      Newsletter   Newsletter? @relation(fields: [newsletterId], references: [id])
      newsletterId Int?
    }
    What’s the best way to implement my use case?
    e
    • 2
    • 3
  • e

    EdwinJr

    05/29/2022, 6:31 PM
    Hey guys, wha'ts up ? I'm having a hard time using group by. I have a model of users which have properties like language and school uid. I want to a query which groups users who have the same school and languages. Here is my query:
    this.prisma.users.groupBy({
    by: ["uid","language", "school"]
    })
    Yet the only result I get is:
    [
    { uid: 23, language: 'english', "school":"A "},
    { uid: 22, primary_language: 'french', "school":"B" },
    { uid: 24, primary_language: 'french' , "school":"B"}
    ]
    Do you guys have any idea of how I can really group by school and name ? I have a result like:
    [
    [{ uid: 23, language: 'english', "school":"A "}],
    [{ uid: 24, language: 'french', "school":"B "},  { uid: 22, language: 'french', "school":"B "}],
    ]
    Thank you !! 🙂
    b
    n
    v
    • 4
    • 5
  • a

    Awey

    05/30/2022, 12:41 AM
    To anyone familiar with NestJS, is there a happy medium between the Prisma generated types and a class validator to verify your input data? Most examples I've seen you either use the Prisma generated types or you create a DTO that uses
    class-validator
    .
    ✅ 1
    k
    j
    +2
    • 5
    • 6
  • w

    Wahyu

    05/30/2022, 1:37 AM
    need help, how do I search
    findMany
    where the entity is not referenced by any other entity. I have a model called RenewalStorage that is a pivot table between Renewal <-> Storage models, I want to find Storage that is not referenced in any RenewalStorage
    ✅ 1
    k
    • 2
    • 2
  • k

    Kasir Barati

    05/30/2022, 8:30 AM
    prisma sync and async api As you all know prisma returns Promise but I wanna to have the ability to tell prisma that this query should be executed synchronous not asynchronous. Any thought?
    👀 1
    j
    n
    • 3
    • 10
  • d

    Dominik Jašek

    05/30/2022, 9:48 AM
    Hi, from clean architecture point of view: I am using Nest.js. What is the cleanest and most correct way to acces db from a service? Can I use prismaService using Dependency Injection or should I create a facade which encapsulates the ORM so I can replace that in the future with another one?
    ✅ 1
    n
    • 2
    • 1
  • v

    Vivek Poddar

    05/30/2022, 10:01 AM
    I have the following schema definition:
    Copy code
    model Category {
      id          Int       @id @default(autoincrement())
      name        String    @db.VarChar(255)
      description String?   @db.Text
      active      Boolean   @default(true)
      Product     Product[]
    }
    
    model Product {
      id          Int      @id @default(autoincrement())
      createdAt   DateTime @default(now())
      updatedAt   DateTime @updatedAt
      name        String   @db.VarChar(255)
      brand       String   @db.VarChar(255)
      offerPrice  Int      @db.Int
      description String?  @db.Text
      category    Category @relation(fields: [categoryId], references: [id])
      categoryId  Int
    }
    But I don’t see
    category
    attached to the generated type
  • v

    Vivek Poddar

    05/30/2022, 10:01 AM
    Copy code
    /**
     * Model Category
     * 
     */
    export type Category = {
      id: number
      name: string
      description: string | null
      active: boolean
    }
    
    /**
     * Model Product
     * 
     */
    export type Product = {
      id: number
      createdAt: Date
      updatedAt: Date
      name: string
      brand: string
      offerPrice: number
      description: string | null
      categoryId: number
    }
    ✅ 1
    n
    • 2
    • 1
  • b

    Brothak

    05/30/2022, 10:13 AM
    How do you concatenate ORDER BY in Prisma.sql? so I have
    Copy code
    Prisma.sql`Select * from foo where y = ${z};`
    and I would like to have
    Copy code
    Prisma.sql`Select * from foo where y = ${z} ${addOrder ? ORDER BY foo limit 10;" : ";";`
    ✅ 1
    a
    • 2
    • 2
  • b

    Brothak

    05/30/2022, 10:13 AM
    Issue is that when using Prisma.sql ${addOrder} is interpreted as query parameter
  • d

    Davedavedave

    05/30/2022, 12:20 PM
    How do i get ts to infer the proper type for existing?
    Copy code
    // type for existing gets inferred like this: 
    // { id: string | null }[]
    Copy code
    const existing = prisma.users.findMany({
      select: { id: true },
      where: { NOT: { id: null } }
    })
    I tried to use Prisma validators with a validator for select and a seperate for where or one for the FindManyArgs type, but this didnt seem to work properly. How do I get the correct returnType of string ids in this case? Thanks guys 🙂
    👀 1
    n
    v
    • 3
    • 4
  • j

    Jay Pazos

    05/30/2022, 1:02 PM
    Hi all, I am writing my first CRUD operations with Prisma and Next.js. The schema is simple and in an page on an Next.js API route I am receiving a webhook, that I then deconstruct and want to create tables using the deconstructed variables in a Postgresql database. The problem is that I don't manage to create the data in the tables. The simple Schema is the following:
  • j

    Jay Pazos

    05/30/2022, 1:03 PM
    datasource db { provider = "postgresql" url = env("DATABASE_URL") } generator client { provider = "prisma-client-js" } model User { id String @default(cuid()) @id email String @unique name String createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") orders Order[] @@map("users") } model Order { id String @default(cuid()) @id created_at DateTime @default(now()) user User @relation(fields: [userId], references: [id]) userId String @@map("orders") }
  • j

    Jay Pazos

    05/30/2022, 1:03 PM
    And the page on the Next.js Api route is as follows:
  • j

    Jay Pazos

    05/30/2022, 1:04 PM
    I would appreciate it if somebody can tell me what I am doing wrong,
  • j

    Jay Pazos

    05/30/2022, 1:04 PM
    Best.
  • j

    Jay Pazos

    05/30/2022, 1:04 PM
    Jay
  • j

    Jay Pazos

    05/30/2022, 1:06 PM
    import type { NextApiRequest, NextApiResponse } from 'next' import prisma from '../../lib/prisma' export default async function handler(req: NextApiRequest, res: NextApiResponse) { //deconstrucion of webhook pointing to api/order page const {email,name, userId} = req.body // conversion of num type to string type in the userID field, to be coherent with id String type let userIdst= userId.toString(10) //So far so good, console.log works console.log(email, name, userIdst) try { let checkUser = await prisma.user.findUnique({ where: { email: email, }, }) if (checkUser === null) { await prisma.user.create({ data: { email: email, name: name }, }) } else { await prisma.order.create({ data: { userId: userIdst, }, }) } res.status(200).json({ message: 'Succeeded to create records!' }) } catch (error) { res.status(500).json({ error: 'Failed to create records!' }) } }
    👀 1
    a
    a
    • 3
    • 4
  • s

    Songkeys

    05/30/2022, 1:30 PM
    Hi. May I ask question here? I'm using
    connect
    to create relational model as described in doc:
    Copy code
    const user = await prisma.profile.create({
      data: {
        bio: 'Hello World',
        user: {
          connect: { email: '<mailto:alice@prisma.io|alice@prisma.io>' },
        },
      },
    })
    I also disabled foreign keys using
    previewFeatures = ["referentialIntegrity"]
    and
    referentialIntegrity = "prisma"
    . But it still give me error when the
    connect
    field is not existed:
    Copy code
    An operation failed because it depends on one or more records that were required but not found.
    Is there any way that I could disable this validation? I only want this relational model when querying, not when inserting and strictly validating my create input. Thank you so much! edit: i post this here https://github.com/prisma/prisma/discussions/13565
    ✅ 1
  • s

    Simon Thow

    05/30/2022, 1:41 PM
    Hi i am having issues with the database connection. I am having to manually set the url within the code which isn’t optimal.
    👀 1
    n
    s
    • 3
    • 6
  • m

    Michael Roberts

    05/30/2022, 2:10 PM
    Hi, I’m basically writing some composed utility functions for the prisma fetching … e,g.,:
  • m

    Michael Roberts

    05/30/2022, 2:10 PM
    Copy code
    export const findManyTelescopes = async (prisma: PrismaClient) => {
      return await prisma.telescope.findMany({
        select: selectPublicFieldsForTelescope
      })
    }
  • m

    Michael Roberts

    05/30/2022, 2:11 PM
    But I want to pass in things like select / where / exclude etc … is there a way I can infer these types from Prisma at all?
    ✅ 1
    r
    • 2
    • 1
  • r

    Rubén Lopez Lozoya

    05/30/2022, 2:33 PM
    Hey team, we stumbled across an issue when trying to run Promise.all() within a $transaction and rolling back once a promise fails. This is what our implementation looks like:
    Copy code
    prisma.$transaction((prisma) => async {
       const updates = items.map((item) => {
          prisma.updateMany(....)
       });
       await Promise.all(updates);
    })
    } catch (err) {
      // Handle the rollback...
    }
    if any of the promises rejects, the transaction will rollback but only all the operations that happened before the failing one. The rest of the operations that are being executed as part of the Promise.all() will still reach the database, leaving us with an undesired partial update. I would expect ORMs to handle this situation for me and somehow disregard/rollback all ongoing operations after one of the promises inside a transaction fails. I am wondering if what I want to achieve can be done using Prisma out of the box or if I will have to play around with Promise.allSettled API (or just going full sequential) to get what I want.
    a
    • 2
    • 3
  • f

    FUTC

    05/30/2022, 8:02 PM
    How would I go about implementing a transactions for graphql with NestJS? I want to implement transactions so all mutations that are in a GQL request (because you can send multiple mutations at once) run in the same transaction, so that if one mutation fails, the transaction is rolled back. Does anybody have any information on how I can best implement this in NestJS?
    ✅ 1
    n
    • 2
    • 1
  • r

    rcastell

    05/30/2022, 8:11 PM
    Hi. How can i read or print the query what a im doing in prisma? Are there any method to do it? Thanks!
    ✅ 1
    j
    o
    • 3
    • 2
1...580581582...637Latest