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

    Nicholas Ewing

    09/09/2022, 12:51 PM
    Also, what's the appropriate channel for asking schema questions?
    ✅ 1
    n
    • 2
    • 1
  • m

    Michael

    09/09/2022, 2:26 PM
    Hi, I'm writing some audit log middleware that uses a transaction. Is there a way I can either call
    next(params)
    in the transaction then create my log entry insert? Or is there another way to convert
    next(params)
    to a proper query that
    prisma.$transaction()
    can understand?
    👀 1
    a
    v
    • 3
    • 2
  • d

    dimidev

    09/09/2022, 3:45 PM
    hi, is there any better way to handle prisma client erors? other than that
    Copy code
    if (
            e instanceof Prisma.PrismaClientKnownRequestError &&
            e.code === 'P2002'
          ) {
            throw new ConflictException("Email already used"));
          } else {
            throw new Error(e);
          }
    ✅ 1
    h
    • 2
    • 1
  • d

    dimidev

    09/09/2022, 3:47 PM
    if i use e.message i get this.. and its not very pleasable..
    Copy code
    Invalid `this.prisma.user.create()` invocation in
    /root/Code/watergems-cloud/api/src/auth/auth.service.ts:51:43
    
      48 
      49 try {
      50   // ! SignUp can do only users
    → 51   const user = await this.prisma.user.create(
      Unique constraint failed on the fields: (`email`)
  • d

    dimidev

    09/09/2022, 3:47 PM
    so, is there any way to get only "Unique constraint failed on the fields: (
    email
    )" without the traceback?
  • o

    Ofir Cohen

    09/09/2022, 8:55 PM
    Hi, is it good practice to check-in the auto-generated clients generated by
    npx prisma generate
    to Git, or should I run this command as part of my
    prestart
    step in
    npm
    ? Context: I am deploying my web app in an air-gapped system and the
    npx prisma generate
    tried to fetch some files from an online URL and failed miserably. Now I’m debating between: 1. Runing
    npx prisma generate
    as part of the Docker build - to online fetch the auto-generated files 2. Checking-in the prisma client to Git
    ✅ 1
    o
    h
    • 3
    • 3
  • h

    Harris Rothaermel

    09/09/2022, 11:20 PM
    Hi all, is it possible to create a uniqueness constraint based on the values of a field?
    Copy code
    model Conversation {
      id           String    @id @default(uuid())
      channelId    String
      active       Boolean   @default(true)
      messages     Message[]
      participants User[]
      summary      String?
      createdAt    DateTime  @default(now())
      updatedAt    DateTime  @updatedAt
    
      @@unique([channelId, active], name: "active_conversation")
    }
    I was hoping to create a constraint that there is only ever 1 active (active = true) conversation in a channel, but I realized is that with the constraint as shown above, it actually prevents non-active conversations from being stored if there is already a non-active conversation in the same channel
    ✅ 1
    h
    • 2
    • 1
  • o

    Ofir Cohen

    09/09/2022, 11:30 PM
    In simpler words, should Prisma client be version controlled (Git) or auto-generated through
    npx prisma generate
    on
    npm run dev
    ?
    ✅ 1
    r
    • 2
    • 1
  • o

    Ofir Cohen

    09/10/2022, 12:35 AM
    I now realize that what failed is the query engine download, I could cache it locally or simply run
    npx prisma generate
    as part of the Docker build step and have it cached as a side effect.
    ✅ 1
    r
    • 2
    • 6
  • d

    David Wagner

    09/10/2022, 12:33 PM
    Hello everyone. I'm just playing around so I can learn Prisma and playing with different scenarios. There has to be a flaw in my logic here but I can't see it. This code is supposed to take the categories from the trivia db api and put them in the database however, as you'll see from the Gist it's only storing the last category in the list. https://gist.github.com/Dave-Wagner/09dc44963d85867a0b7980594c511ef1
    👀 1
    a
    v
    • 3
    • 2
  • p

    Paulo Castellano

    09/10/2022, 5:05 PM
    its possible have 2 connections in one app? mongo + postgres
    ✅ 1
    h
    • 2
    • 1
  • s

    Slackbot

    09/11/2022, 6:31 AM
    This message was deleted.
    d
    • 2
    • 1
  • o

    Omar

    09/11/2022, 6:44 AM
    Hey all, I'm using prisma with trpc, zod and nextjs. I have 2 models on my prisma schema as such:
    Copy code
    model Poll {
      id        String   @id @default(cuid())
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
      text      String
      endsAt DateTime?
      ownerToken String @db.VarChar(255)
      options Option[]
    }
    
    
    model Option {
      id        String   @id @default(cuid())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      text       String
      votes      Int      @default(0)
      voterToken String @db.VarChar(255)
      poll Poll @relation(fields: [pollId], references: [id])
      pollId String
    }
    I'd like to be able to create a poll with the associated options to it but having a hard time maybe with my lack of understanding. How can I create the options mutation? where do I get the poll id from if we haven't created it yet and same goes for the voter token?
    Copy code
    export const pollRouter = createRouter().mutation("create", { //>>>> is this validator right?
        input: z.object({
          text: z.string().min(5).max(600),
          options: z
            .array(z.object({ text: z.string().min(2).max(500) }))
            .min(2)
            .max(5),
          endsAt: z.string(),
        },
        async resolve({ input, ctx }) {
          if (!ctx.token) throw new Error("Unauthorized");
          return await prisma.poll.create({
            data: {
              text: input.text,
              ownerToken: ctx.token,
              endsAt: input.endsAt,
              options: { // I am stuck here on how to create the options
                create: await prisma.option.create({
                  data: {
                    text: input.text,
                    voterToken: ctx.token,
                    poll: 
                  }
                })
              },
            },
            include: {
              options: true,
            },
          });
        },
      });
    • Is my validation correct? • Where do I get the
    pollId
    that the options belong to? • How do I get the mutation to go through if initially I don't have a
    voterToken
    ?
    ✅ 1
    h
    v
    • 3
    • 2
  • r

    Rexford Koomson

    09/11/2022, 7:38 AM
    Hello Team, I would like to find out how thus Nexus code first support federation directive. I am building a Graphql API with Prisam and Nexus on apollo server. I need a solution to include the apollo federation directive example: @key(field: "id") or @extend to my graph generated graph by nexus. Thank you ❣️
    ✅ 1
    h
    • 2
    • 1
  • m

    Minimal Sportswear

    09/11/2022, 11:08 AM
    how do I get prisma seed.ts working in nextjs? using esmodule doesn't work and using commonjs gives error
    👀 1
    o
    v
    • 3
    • 3
  • o

    Omri Katz

    09/11/2022, 11:55 AM
    I used ts-node
  • o

    Omri Katz

    09/11/2022, 11:55 AM
    is with typescript?
    👀 1
    v
    • 2
    • 1
  • g

    Gal Elmalah

    09/11/2022, 12:22 PM
    Hey wonderful people, I have a quick question regarding Prisma.io nodejs client, I noticed that there is a “Pricing” section in the site and I’m wondering if it includes some cloud solution or its just for the usage of the ORM and if so, can you elaborate a bit on how you measure our usage? Thanks! Seems like I miss-understood the pricing page and its only for the “data-proxy” product 🙂
    ✅ 1
    h
    • 2
    • 2
  • j

    juls07

    09/12/2022, 5:28 AM
    how should I use the
    AND
    in a delete case? trying to do something like
    Copy code
    await prisma.like.delete({
      where: {
        AND: [
          {
            postId: postId
          },
          {
            userId: ctx.user.userId
          }
        ]
      }
    })
    ✅ 1
    h
    c
    v
    • 4
    • 5
  • j

    juls07

    09/12/2022, 5:30 AM
    just doesnt work
  • s

    Simon Sardorf

    09/12/2022, 9:56 AM
    How do you folks deal with floating point rounding issues? I’ve tried to attach my problem here. Basically I am adding 0.001 every time, and there are floating point rounding errors, which is obviously a problem.
    Copy code
    await prisma.cryptoaddress.update({
                    where: {
                        address: address,
                    },
                    data: {
                        balance: {
                            increment: parseFloat(amount),
                        },
                    },
                  });
    ✅ 1
    v
    h
    • 3
    • 3
  • r

    Richard

    09/12/2022, 11:00 AM
    What’s the simplest analytics tool for mongodb events? No client side events, only a view of weekly active users + some events that live exclusively in mongo. Bonus if it syncs some events to slack.
    👀 1
    v
    • 2
    • 4
  • m

    Michael Roberts

    09/12/2022, 11:54 AM
    Hey 👋 I’m wondering, is there something similar to this sort of API for database transactions:
    Copy code
    const transactionId = prisma.trasaction()
    
    prisma.user.create()
    
    try {
       prisma.session.create()
    } catch {
       prisma.rollback(transactionId)
    }
    ✅ 1
    a
    v
    • 3
    • 5
  • m

    Mattèo Gauthier

    09/12/2022, 11:54 AM
    Hey 🙌 Does someone know how to check connection status with prisma client (like an healthcheck) ?
    ✅ 1
    r
    • 2
    • 3
  • a

    Ali

    09/12/2022, 12:43 PM
    Hello I have a problem with prisma studio. when I'm on prisma studio this is not the updated database. This is my database before the migration. Do you know what can be the problem?
    ✅ 1
    n
    • 2
    • 7
  • k

    Kelly Copley

    09/12/2022, 1:45 PM
    So these (not available) for column names make things are super helpful for debugging... 😂
    Copy code
    'Error: Unique constraint failed on the (not available)',
    👀 1
    a
    • 2
    • 1
  • s

    Shaked Fried

    09/12/2022, 2:00 PM
    Hi all, Regarding the Prisma multi schema feature, As I understand it, duplicate table names across schemas isn’t supported at the moment. Would you be able to provide an ETA on that? We are currently conducting a POC for several ORMs and I would like to try Prisma as one of our options Thanks!
    ✅ 1
    n
    • 2
    • 5
  • k

    Kay Khan

    09/12/2022, 2:16 PM
    Anyone who works with mongodb and prisma came across -
    Copy code
    Error occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: \"unknown\", message: \"Operation timed out (os error 110)\" } })
    The mongodb official docs make mention of a
    socketTimeoutMS
    https://www.mongodb.com/docs/v5.0/reference/connection-string/#mongodb-urioption-urioption.socketTimeoutMS but they say the default is to never timeout although it might vary depending on the driver. So im wondering if the underlining driver which prisma uses has this value set and if its possible to change.
    ✅ 1
    j
    • 2
    • 8
  • g

    Geebrox

    09/12/2022, 2:38 PM
    how to prioritize
    OR
    filter? I have multiple docs where both
    OR
    could return true. But I want to prioritize only one of them if both are true. e.g.: I have field
    isEmpty: boolean
    and
    accountId: string?
    I want to get where
    accountId
    is defined and
    isEmpty
    is
    false
    or where
    accountId
    is not defined and
    isEmpty
    is true. In some cases both of them are true, and in such cases I want to get first conditions result. Please, advice
  • g

    Geebrox

    09/12/2022, 2:41 PM
    Copy code
    const card = await this.prismaService.card.findFirst({
          where: {
            locale: account.locale,
            OR: [
              { AND: [{ isEmptyCard: false }, { accountId: account.id }] },
              { isEmptyCard: true },
            ],
          },
        });
    I use this code, and when both
    OR
    conditions are true, it returns the result of the last one
    ✅ 1
    j
    • 2
    • 5
1...619620621...637Latest