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

    MrDell

    07/11/2022, 4:11 PM
    The Database is completely fresh and has no record of data in it and the id, which i assigned in the code is 10 digital long and in the form of String.
  • e

    Edun omatseye

    07/11/2022, 4:22 PM
    hello @MrDell any particular reason why you are not using the attribute • @default(uuid()) or • @default(cuid()) or • @default(autoincrement()) in the id field?
  • e

    Edun omatseye

    07/11/2022, 4:22 PM
    this way you can do without passing a value into the id field when creating a record eg
  • e

    Edun omatseye

    07/11/2022, 4:23 PM
    Copy code
    await prisma.player.create({
        data: {
            region: region,
            timezone: REGION[region][country]["timezone"],
            country: country,
        }
    }),
  • m

    MrDell

    07/11/2022, 4:24 PM
    There's specific reason behind it. I am getting ID from some APIs and i am storing the ID of users so that i can fetch them later on whenever details changes.
  • m

    MrDell

    07/11/2022, 4:24 PM
    Should i store them in different columm?
  • e

    Edun omatseye

    07/11/2022, 4:25 PM
    i see what you mean, but the api cant be sure if values coming from that api can be totally unique, so the model require at least one unique field
  • m

    MrDell

    07/11/2022, 4:25 PM
    I see, what should be solution for this?
  • e

    Edun omatseye

    07/11/2022, 4:25 PM
    by using the unique @unique() attribute on any unique field
  • m

    MrDell

    07/11/2022, 4:26 PM
    Gotcha! I'II implement it in schema. Thanks for the input.
  • l

    Lars Ivar Igesund

    07/11/2022, 4:28 PM
    You may still want to have a default generated id, then have a unique field externalId or similar.
  • e

    Edun omatseye

    07/11/2022, 4:28 PM
    again, not sure of the BigInt as type you have in your schema? should just be Int
  • m

    Michael Jay

    07/11/2022, 4:28 PM
    @MrDell - it seems to me that Prisma may be complaining because you can't enforce uniqueness on a passed-in string. I'm watching the topic for clarification. @Edun omatseye If I can piggy-back on this question (because I'm in a similar place) - what do you do if you need to create a record and then another record which references it, and you want to do it in a transaction? If the foreign key of B references the id of A, then you have to have the id of A to create the record for B. It seems to me that if you can define the PK on A and use it as the FK on B, then you can put both queries in a $transaction. But if you can't, then you have to wait for the return from the creation of A to create B.
  • e

    Edun omatseye

    07/11/2022, 4:29 PM
    Copy code
    model Player {
        id           Int      @id
        createdAt    DateTime?   @default(now())
        region       String
        country      String
        timezone     String
        Tournaments Tournament[]
    }
  • m

    MrDell

    07/11/2022, 4:29 PM
    Reason of using BigInt instead of int is due to fact that i am getting a number which is around 10-13 digital long.
  • m

    MrDell

    07/11/2022, 4:30 PM
    Int has range of -2147483648 to +2147483647 and it was showing -x_number when i stored with int.
  • e

    Edun omatseye

    07/11/2022, 4:31 PM
    Working with BigInt
    BigInt
    fields are represented by the `BigInt` type (Node.js 10.4.0+ required). The following example demonstrates how to use the
    BigInt
    type:
    Copy code
    import { PrismaClient, Prisma } from '@prisma/client'
    
    const newTypes = await prisma.sample.create({
      data: {
        revenue: BigInt(534543543534),
      },
    })
  • m

    MrDell

    07/11/2022, 4:33 PM
    I see, my bad there. I should have gone for BigInt in explicit conversion.
    👀 1
  • m

    MrDell

    07/11/2022, 4:39 PM
    I've tried to use "@unique" at the ID field and it doesn't seems to work neither. Should i let Prisma to take care of PK and make unique column on the API ID itself?
  • m

    MrDell

    07/11/2022, 4:40 PM
    As for BigInt, it showed better accuracy with ID which I was storing before in database.
    ✅ 2
    n
    m
    • 3
    • 9
  • h

    Harsh Singh

    07/11/2022, 8:43 PM
    I was curious, but what's the reason behind the Prisma logo being grey on YouTube? Is it an issue with YouTube, or was that done on purpose?
    ✅ 1
    n
    • 2
    • 2
  • z

    Zichen

    07/11/2022, 8:58 PM
    Copy code
    18:00:54  Environment variables loaded from .env
    18:00:54  Prisma schema loaded from prisma/schema.prisma
    18:00:55  thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
    18:00:55    left: `22`,
    18:00:55   right: `0`', library/std/src/sys/unix/locks/pthread_condvar.rs:63:9
    18:00:55  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    18:00:55  fatal runtime error: failed to initiate panic, error 5
    👀 1
    n
    • 2
    • 1
  • z

    Zichen

    07/11/2022, 8:58 PM
    Hello Guys, I cannot run the npm generate on Ubuntu machine with the latest prisma 4.0, it was working with Prisma 3.5
  • v

    Viktor Suchý

    07/12/2022, 5:46 AM
    Hello Guys, I have a problem with generated types. I can’t import them from @prisma/client package. I’m using pnpm as my package manager. Thanks for help
    👀 1
    a
    v
    • 3
    • 2
  • v

    Viktor Suchý

    07/12/2022, 5:48 AM
  • s

    suraj sunny

    07/12/2022, 2:02 PM
    Im having an issue to connect prisma to aws lambda, can anyone please help me with this issue? any help would be appreciated.
    ✅ 1
    m
    • 2
    • 5
  • s

    Satont

    07/12/2022, 9:51 PM
    Hey guys, i have followed schema: How i can find channels where command with some name not exists. Like Commands have
    [{ id: '123', name: 'first'}]
    , i wan't to find channels where command with
    name
    second
    not exists, but not others channels.
    Copy code
    model Channel {
      id String @id
    
      commands           Command[]
    
      @@map("channels")
    }
    
    model Command {
      id String @id @default(dbgenerated("gen_random_uuid()"))
      name         String
      channelId    String
      channel   Channel        @relation(fields: [channelId], references: [id])
      @@map("channels_commands")
    }
    👀 1
    n
    • 2
    • 2
  • j

    Jared Fraser

    07/13/2022, 6:00 AM
    Due to some legacy DB design, we have some fields that are defined as a
    string
    in the DB but have constraints placed on the field at the DB level to restrict the values to a set (just like an enum). In previous versions of Prisma, we defined these in our schema as an
    enum
    and all was well, it worked perfectly. However in trying to upgrade to Prisma 4, we've started to get the error
    Copy code
    meta: {
        code: 'XXUUU',
        message: 'db error: ERROR: cannot create enum of unspecified type'
      },
    Which I'm assuming is that Prisma no longer knows how to cast the string db value to the enum defined in the schema. Any tips for how to progress? Any way to define a string value in prisma with a set of possible string values?
    ✅ 1
    j
    • 2
    • 5
  • m

    Martí Crespí

    07/13/2022, 6:51 AM
    Hi! How you serialize one bigint property? I have installed the
    graphql-scalars
    package and I'm using like this
    Copy code
    @Field(() => GraphQLScalars.BigIntResolver, {
        nullable: true
      })
      lte?: bigint | undefined;
    But when it's not null I recieved an error
    Copy code
    "message": "Do not know how to serialize a BigInt"
    Any approach to fix it or how serialize it properly?
    ✅ 1
    j
    • 2
    • 6
  • s

    spohl

    07/13/2022, 12:39 PM
    Hi, can i get an advise how to best return all data which is not null or false? deleted: { not: true, }, Will not return fields with null: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#remarks-21 Do i really have to do: where: { OR: [ { deleted: null }, { deleted: false }, ], },
    ✅ 1
    r
    n
    • 3
    • 3
1...596597598...637Latest