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

    Lewis

    08/29/2022, 1:09 PM
    Copy code
    model User {
      id        String   @id @unique
      rewardsId String   @unique
      rewards   Rewards  @relation(fields: [rewardsId], references: [id])
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    }
    
    model Rewards {
      id      String @id @unique
      user    User?
      test    Int @default(0)
    }
    Hello! I need some help and can't seem to find the answer online. I'm trying to create a 1-1 relation and have the "Rewards" table automatically populate once I create a User like this:
    user.create({data: {id: "id"}})
    Without having to specify in code to also create the Rewards table? I'm also wondering how when the Rewards table is created it can share the id from User? Also... is there a way to edit the DateTime default to be something other than "now" in the schema? Say 24 hours in the past?
    šŸ‘€ 1
    a
    s
    • 3
    • 2
  • s

    Stanislas de Roquemaurel Galitzine

    08/29/2022, 1:58 PM
    Hello fellow Prisma-ers! I have a question pertaining to testing when using the Prisma dataproxy. How is testing usually handled? I am facing the exact same problem described in this Prisma GH issue: https://github.com/prisma/prisma/issues/11526#issuecomment-1055968251 Should we just set the url to MIGRATE_DATABASE_URL ?
    āœ… 1
    j
    • 2
    • 4
  • d

    Dondo Chaka

    08/29/2022, 5:59 PM
    Hi all, I'm working on a pub/sub feature where the party sending or receiving a message can be one of multiple model types. Is there a better way to model this? For example, is there a way to replace
    target_type
    and
    target_id
    with relations to the corresponding
    User
    and
    Channel
    models (not shown)?
    Copy code
    model Topic {
      id          Int            @id @default(autoincrement())
      name        String
      description String?
      publishers  Communicator[] @relation("publisher")
      subscribers Communicator[] @relation("subscriber")
    }
    
    model Communicator {
      id            Int              @id @default(autoincrement())
      target_type   CommunicatorType
      target_id     Int
      publishable   Topic[]          @relation("publisher")
      subscriptions Topic[]          @relation("subscriber")
    }
    
    enum CommunicatorType {
      USER
      CHANNEL
    }
    āœ… 1
    n
    • 2
    • 2
  • f

    Filipe

    08/29/2022, 8:04 PM
    āœŒļø Oh, hello! Can Someone help me. I have models for each pc component like Motherboard, CPU, GPU, etc... Each component can be available in multiple stores. How do I make this relation between each component and each store. Using MySql.
    enum StoreNames {
    GlobalData PcDiga PcComponentes } model Store { id String @id @default(cuid()) name StoreNames product_url String @default("") price Float @default(0) discount Int? availability Boolean? created_at DateTime @default(now()) updated_at DateTime @updatedAt }
    model Cpu {
    id String @id @default(cuid()) product_type String @default("cpu") name String abrev String created_at DateTime @default(now()) updated_at DateTime @updatedAt } model Motherboard { id String @id @default(cuid()) product_type String @default("motherboard") name String abrev String created_at DateTime @default(now()) updated_at DateTime @updatedAt }
    g
    • 2
    • 1
  • t

    Timothy Choi

    08/29/2022, 9:00 PM
    Hi, is Prisma able to generate native TypeScript enums somehow?
    āœ… 1
    g
    n
    • 3
    • 3
  • c

    ClƩment Guibout

    08/29/2022, 9:00 PM
    Hello guys, It's been a while since I am stuck on the same problem I have a model as
    Copy code
    model Pinpoint {
        id          String     @id @default(cuid())
        name        String
        description String?
        carrousel   Image[]
        date        DateTime?
        latitude    Float
        longitude   Float
        createdAt   DateTime   @default(now())
        updatedAt   DateTime   @updatedAt
    }
    
    model Image {
        id          String    @id @default(cuid())
        name        String
        description String?
        image       String
        pinpoint    Pinpoint  @relation(fields: [pinpointId], references: [id], onDelete: Cascade)
        pinpointId  String
    }
    And I am trying to create a new pinpoint with the associated image carrousel using TRPC and Prisma Here is my attempt (that should work?)
    Copy code
    export const pinpointRouter = createRouter()
      .mutation("createPinpoint", {
        input: z.object({
          name: z.string(),
          description: z.string().optional(),
          carrousel: z.array(z.object({
            name: z.string(),
            description: z.string().optional(),
            image: z.string(),
          })).optional(),
          date: z.date().optional(),
          latitude: z.number(),
          longitude: z.number()
        }),
        async resolve({ ctx, input }) {
          try {
            await ctx.prisma.pinpoint.create({
              data: {
                name: input.name,
                description: input.description,
                carrousel: {
                  create: input.carrousel
                },
                date: input.date,
                latitude: input.latitude,
                longitude: input.longitude,
                
              },
              include: {
                carrousel: true
              }
            })
          } catch (error) {
            console.log(error)
          }
        }
      });
    I am first describing the zod schema I want tRPC to validate, and the I try to effectively create the record in the database But the carrousel create instruction tells me that
    Type '{ description?: string | undefined; name: string; image: string; }[] | undefined' is not assignable to type '(Without<ImageCreateWithoutPinpointInput
    , where the former is my actual carrousel that I receive on the API, and the later is what should be described in the database. Aren't these two things the exact same type?
    šŸ‘€ 1
    n
    • 2
    • 1
  • d

    David Ilizarov

    08/29/2022, 10:43 PM
    Is there really no good way to update a unique row in a DB based on additional non-unique values?
    Copy code
    prisma.document.update({
      where: {
        id, //unique
        creatorId: session.userId, // non-unique
        state: "DRAFTING" // non-unique
      }
    })
    Seems really really strange you can't do this. Yes, a unique row stays required. Worst case is you don't find a row that meets those conditions and do nothing. My case is rather minor, but there are other cases where without this, race-conditions and security vulnerabilities are introduced.
    āœ… 1
    n
    • 2
    • 5
  • i

    Ilkka Huotari

    08/30/2022, 12:32 AM
    Hi there. New to Prisma. When I create records into the database (Mongo) that had a field set as
    @unique
    , it can still create multiplerecords that have the same value in that
    @unique
    field. It throws an error when I'm doing that do
    id
    field, but doesn't throw if I do it with another
    @unique
    field. So, it seems to ignore that
    @unique
    setting for all the other fields than
    id
    . Solution: I had to create a unique index in Mongo shell to make the unique thing work.
    āœ… 1
    r
    n
    • 3
    • 3
  • r

    Rain

    08/30/2022, 12:57 AM
    Not really prisma related question, if i use interactive transaction to count table rows and do an insert to the table, will it have a race condition if the transaction executed concurrently in the same time ? basically i want to limit the amount of rows can be created but i think if there is 2 transaction running concurrently it can end up as having more than the limit.
    d
    • 2
    • 26
  • p

    Petr SlavĆ­k

    08/30/2022, 8:53 AM
    Hi everybody. I'm having problems connecting to MySQL server from Firebase Function (basically Google Cloud Function) and it's a strange one. Every connection attempt ends with `errorCode: P1001, Can't reach database server at `db.al21.savana-hosting.cz`:`10076`` If i set
    pool_timeout=30&connect_timeout=30
    , it ends up with
    errorCode: P2024, Timed out fetching a new connection from the connection pool.
    Now the strange part: āœ“ Local machine - Connection works perfectly from Firebase Emulator -> connection string is valid āœ“ Remote Firebase Function - I can successfully connect to that DB via https://github.com/sidorares/node-mysql2 with same credentials -> nothing is preventing connection from the Firebase Function So the question is, why can't I connect with Prisma while I can with mysql2? I am using Prisma 4.2.1.
    āœ… 1
    n
    • 2
    • 6
  • a

    Anthony

    08/30/2022, 9:45 AM
    Hi, i’m facing a weird error when trying to migrate my schema, i’m just getting back ā€˜Error : Migration engine error’ with npx prisma migrate dev command I’m on ubuntu 22.04 and using Prisma 4.2.1
    šŸ‘€ 1
    r
    n
    • 3
    • 2
  • i

    Ilkka Huotari

    08/30/2022, 11:02 AM
    Copy code
    Message: Error in Prisma Client request: 
    
    Maximum call stack size exceeded
      
    Query:
    {
      "modelName": "Email",
      "operation": "findMany",
      "args": {
        "take": 100,
        "skip": 0,
        "select": {
          "id": true,
          "uid": true,
          "userId": true,
          "contactId": true,
          "contactStatus": true,
          "messageId": true,
          "to": true,
          "cc": true,
          "bcc": true,
          "createdAt": true,
          "updatedAt": true,
          "headers": true,
          "subject": true,
          "text": true,
          "html": true,
          "textAsHtml": true,
          "exct": true,
          "files": true,
          "tags": true,
          "status": true
        }
      }
    }
    r
    • 2
    • 11
  • t

    Travis James

    08/30/2022, 11:04 AM
    Good morning! I am dropping this message in #general just because I don't know where else to put it. I am working on creating a way to use the Prisma Engine in Flutter on a mobile device. This would allow me to query local SQLite data stores with GraphQL (as well as generate Dart code from the
    generate
    action), which is powerful when considering the need for mobile applications to implement offline operation in a transparent way. One key to this for me, however, is the need to encrypt data at rest using SQLCipher. The Prisma Engine has the capability to do this thanks to updates made to
    rusqlite
    that provides support for integrating SQLCipher, but the engine currently does not expose a way to provide keys for decryption (which would be stored securely on the device elsewhere). The question I have is this: is making this change interesting enough to add to the prisma-engines project once I have completed the work?
    āœ… 1
    e
    n
    • 3
    • 4
  • m

    MƔrcio Martins

    08/30/2022, 2:16 PM
    Hey guys, I am running into an issue with Prima 4.2.1. Somehow I cannot create a record by setting the id of the reference directly in the field, instead of using a
    connect
    . This is working for all my other models, but somehow it is not working for this one.
    šŸ‘€ 1
    n
    • 2
    • 2
  • p

    Paul Van Dyk

    08/30/2022, 2:18 PM
    Hey everyone, šŸ‘‹ I'm looking for a little architecting advice, šŸ™ I want to create a field that needs to be a unique relationship across two different tables. So the slug in
    IdentitySlug
    should always be unique, and only exist in one Company entry or one User entry. I'm unsure how to setup the relationship for this, or even if it's possible to setup a relationship for this? I'm using mysql
    āœ… 1
    i
    r
    n
    • 4
    • 4
  • t

    Ted Joe

    08/30/2022, 3:59 PM
    How can I have either nested enums, or have a 3rd enum contain all values from 2 existing enums?
    āœ… 1
    a
    • 2
    • 1
  • p

    prisma chobo

    08/30/2022, 5:27 PM
    Hey @everyone this is elong ma~
    šŸ‘€ 1
    v
    • 2
    • 1
  • d

    David Brands

    08/30/2022, 6:07 PM
    Does anyone know the status of this? https://github.com/prisma/prisma/issues/8446
    āœ… 1
    a
    • 2
    • 3
  • e

    Ennabah

    08/30/2022, 7:07 PM
    Hey everyone! I’m not sure if this is the right channel to ask this question, but what do you guys think of having a channel for contributions and discussions of picking up bugs? Perhaps asking questions on where to start on a specific bug I tried going through the channels list, but it seems it doesn’t exist or it’s marked as private
    āœ… 1
    v
    • 2
    • 5
  • d

    Donald MartĆ­nez Arancibia

    08/30/2022, 7:43 PM
    Hello, I need help, I can't understand how prisma and graphql works. I would really appreciate if you can help me with the automatic updating of a record from a "strong" table when creating a new one from a related table... This is a code that I have followed to make my application: https://github.com/H-Richard/backend-2022 what i want to achieve is to update a field of a selected record by id from the owners table when creating a new record of a dog that has that owner id associated with the dog
    āœ… 1
    r
    • 2
    • 3
  • i

    Ignatius Hefer

    08/30/2022, 7:45 PM
    Hey everyone: I'm running a simple select * on table and comparing knex and prisma performance since my graphql resolvers are taking longer than expected: KNEX
    Copy code
    DEBUG=knex*
    Output:
    knex:client acquired connection from pool: __knexUid1 +0ms
    knex:query select * from "mytable" undefined +0ms
    knex:bindings [] undefined +0ms
    knex:client releasing connection to pool: __knexUid1 +610ms
    PRISMA
    Copy code
    prismaClient.$on("query", (e) => {
      console.log(e);
    });
    Output:
    {
    timestamp: 2022-08-30T19:32:49.399Z,
    query: 'select * from mytable',
    params: '[]',
    duration: 955,
    target: 'quaint::connector::metrics'
    }
    I'm consistently loosing 30 - 50% in performance... Can someone tell me what I'm missing or am I looking at these values wrong?
    • 1
    • 4
  • r

    R2D2

    08/30/2022, 10:01 PM
    Hi everyone! Can any body help to understand a problem with connection while prisma download? Sometimes (50%) iw got timeout when primsa try to download file:
    <https://binaries.prisma.sh/all_commits/2920a97877e12e055c1333079b8d19cee7f33826/debian-openssl-1.1.x/introspection-engine.gz.sha256>
    afted 3 days of debuggind, router firmware upgrading, stracing and tcpdumping I find that: domain
    binaries.prisma.sh
    could be resolved to 2 different ips
    108.156.22.32 (<http://server-108-156-22-32.hel51.r.cloudfront.net|server-108-156-22-32.hel51.r.cloudfront.net>)
    108.156.22.92 (<http://server-108-156-22-92.hel51.r.cloudfront.net|server-108-156-22-92.hel51.r.cloudfront.net>)
    and
    108.156.22.32
    did not response on
    :443
    port Im trying from different networks and network providers, its not working. But working only trought vpn in other country. (but
    22.92
    always response succsesfully) (Very annoing thing that makes CI process up to one hour until all TIMEOUTS returns 😫) Command to repro:
    Copy code
    curl <https://binaries.prisma.sh/all_commits/2920a97877e12e055c1333079b8d19cee7f33826/debian-openssl-1.1.x/prisma-fmt.sha256> -v --resolve 'binaries.prisma.sh:443:108.156.22.32'
    
    * Added binaries.prisma.sh:443:108.156.22.32 to DNS cache
    * Hostname binaries.prisma.sh was found in DNS cache
    *   Trying 108.156.22.32:443...
    ... 
    TIMEDOUT
    šŸ‘€ 1
    v
    • 2
    • 2
  • r

    R2D2

    08/30/2022, 10:06 PM
    <!subteam^S01AQUZJZ97|@prismaemployees>
  • g

    Gabriel

    08/30/2022, 11:39 PM
    Hey, a quick and easy one hopefully. I can't find anything in the documentation but what would prismas equivalent be to
    SELECT CONCAT(FirstName, ' ', LastName) AS FullName FROM Users
    ?
    āœ… 1
    g
    n
    • 3
    • 2
  • j

    João Vitor Casarin

    08/31/2022, 1:31 AM
    Hi folks, I hope you're doing good. Knowing that the prisma API methods
    findFirst
    returns
    null
    when not found,
    create
    apparently throws if record exists,
    update
    throws
    RecordNotFound
    when failure,
    delete
    throws
    RecordNotFound
    when failure, what is the advise to standardize these responses? Should I catch the errors and return
    null
    instead of those throws, or analyze if the response is
    null
    and then throw my own error, or what?
    āœ… 1
    a
    • 2
    • 3
  • j

    João Vitor Casarin

    08/31/2022, 1:34 AM
    another question: is it advised to just mock everything related to prisma when testing, or is it better creating a local database to make real queries to it?
    āœ… 1
    n
    • 2
    • 3
  • a

    Alex

    08/31/2022, 7:52 AM
    Hey! I've got a little trouble with my setup, where is the best place to ask for help?
    āœ… 1
    v
    n
    • 3
    • 10
  • a

    Alex

    08/31/2022, 7:52 AM
    specifically related to
    queryRaw
  • a

    Ali

    08/31/2022, 8:33 AM
    Hello, Yesterday Heroku had dns issues and since then I have some mutations that are not working in my app. I have this error on the console when people try to make those mutations:
    Copy code
    provided value for the column is too long for the column's type. Column: (not available)
    Do you know where the problem might come from?
    šŸ‘€ 1
    n
    • 2
    • 7
  • a

    Ali

    08/31/2022, 8:56 AM
    by the way i don't have those problems on my dev and staging environment
1...614615616...637Latest