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

    Logan

    08/23/2022, 11:51 AM
    Hey all. I'm currently having a few difficulties with setting up a relation between two tables in Postgres Prisma client. The following queries are to find the giveaway which the user is trying to enter, and then trying to check if that user has already entered said giveaway. The
    giveawayId
    in the
    giveawayEntry
    table is a foreign key to the
    id
    field in the
    giveaway
    table. I'm not 100% confident in my schema setup - which could be the problem.
    Copy code
    const findGiveaway = await client.prisma.giveaway.findFirst({
        where: {
          messageId: interaction.message.id
        }
      })
    
      const findUser = await client.prisma.giveawayEntry.findFirst({
        where: {
          userId: interaction.user.id,
          giveawayId: findGiveaway.id,
        }
      })
    Copy code
    model Giveaway {
      id                      Int            @id @default(autoincrement())
      messageId               String         @db.VarChar(20)
      GiveawayEntry           GiveawayEntry?
    }
    
    model GiveawayEntry {
      id           Int      @id @default(autoincrement())
      userId       String   @db.VarChar(20)
      giveawayId   Giveaway @relation(fields: [id], references: [id])
    }
    The error is appearing on the line giveawayId: findGiveaway.id, in the second query to check if the user has already entered the giveaway.
    Copy code
    Type 'number' is not assignable to type '(Without<GiveawayRelationFilter, GiveawayWhereInput> & GiveawayWhereInput) | (Without<GiveawayWhereInput, GiveawayRelationFilter> & GiveawayRelationFilter) | undefined'
    ✅ 1
    n
    • 2
    • 7
  • z

    Zahra Mumtaz

    08/23/2022, 12:09 PM
    Hey @all, I am trying to mongo embedded document using Prisma with Nest.js , but unable to figure out how I can achieve this. Any help. Thanks
    ✅ 1
    n
    • 2
    • 7
  • s

    Salman Shaikh

    08/23/2022, 1:32 PM
    Do we have a proper unit testing guide for prisma?
    r
    • 2
    • 15
  • g

    Greg Mckeon

    08/23/2022, 3:48 PM
    Hey everyone! I’m at ReadySet - we’re building a next-gen database cache that speeds up SQL queries and cuts your database costs. All you have to do is swap your connection string - we use your database’s replication stream to keep our cache up-to-date, so there’s no eviction logic or key-value stores required. We just finished support for Prisma and are looking for a few people who want to give us some 👀 and try things out. Ping me if you’d like in - excited to be a part of the community!
    👀 1
    👍 2
    ✅ 1
    prisma rainbow 1
    n
    • 2
    • 1
  • p

    Phorcys

    08/23/2022, 4:05 PM
    it worked properly for me without changes but you should check the guide just to be sure. https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-4
    a
    m
    • 3
    • 2
  • r

    Richard

    08/23/2022, 5:03 PM
    I'm having trouble running
    npx prisma generate
    on a stackblitz repo that contains a prisma schema. Is there another way to run prisma's generator command in the browser? 🤔 Context: I want to generate a DBML schema with this stackblitz via the community generator prisma-dbml-generator Error:
    > Downloading Prisma engines for Node-API for debian-openssl-1.1.x [] 0%
    <- it's stuck here
    ✅ 1
    d
    a
    • 3
    • 3
  • d

    Dave Edelhart

    08/23/2022, 6:30 PM
    when upserting many is there a known reccomendation for maximum number of rows (postgres)? I realize this is a huge and very fuzzy request but — for instance — should you hammer ALL of your data in regardless of the row count? is it better for overall performance to have smaller chunks?
    ✅ 1
    n
    • 2
    • 1
  • d

    Dave Edelhart

    08/23/2022, 7:33 PM
    is there a way to get the current database connection count / max count at runtime?
    ✅ 1
  • h

    HorizonXP

    08/23/2022, 11:29 PM
    Hey folks, I'm running into an issue with Prisma raw queries, that are failing under high load. I cannot recreate it under normal load. The same query eventually succeeds after several attempts. I could understand if the bind parameter actually had an invalid value, but that wouldn't explain why it eventually works. It either consistently works, or doesn't. Bind parameter 26 is either a Prisma.Decimal or null. I'm using queryRawUnsafe `{"clientVersion":"4.2.0","code":"P2010","level":"error","message":"uncaught gql exception Raw query failed. Code:
    22P03
    . Message: `db error: ERROR: incorrect binary data format in bind parameter 26`","meta":{"code":"22P03","message":"db error: ERROR: incorrect binary data format in bind parameter 26"},"stack":"Error: Raw query failed. Code:
    22P03
    . Message: `db error: ERROR: incorrect binary data format in bind parameter 26`\n at RequestHandler.handleRequestError (/home/site/wwwroot/node_modules/@prisma/client/runtime/index.js2883113)\n at RequestHandler.request (/home/site/wwwroot/node_modules/@prisma/client/runtime/index.js2881312)\n at async Proxy._request (/home/site/wwwroot/node_modules/@prisma/client/runtime/index.js2973816)\n at async DeferralService.upsertDeferralChangeLog (/home/site/wwwroot/dist/src/deferral/deferral.service.js37538)\n at async target (/home/site/wwwroot/node_modules/@nestjs/core/helpers/external-context-creator.js7728)\n at async Object.upsertDeferralChangeLog (/home/site/wwwroot/node_modules/@nestjs/core/helpers/external-proxy.js924)","timestamp":"2022-08-23T215556.454Z"}`
    ✅ 1
    n
    • 2
    • 1
  • d

    Dave Edelhart

    08/24/2022, 3:52 AM
    how do you test for array inclusion; given a schema
    Copy code
    model states {
        id                                   String @id
        hindexes                            String[]
        administrative_area_level           Int
        administrative_area_level_1         String
        administrative_area_level_2         String
    }
    If I want to find all states that include a given string in hIndexes, what does the “where” look like?(postgres FWIW)
    ✅ 1
    n
    v
    • 3
    • 5
  • j

    Jijin P

    08/24/2022, 9:27 AM
    Can relational data be created on createMany? if not what’s the best way to do this. Any alternative to looping and inserting?
    ✅ 2
    r
    g
    • 3
    • 2
  • r

    Richard

    08/24/2022, 9:35 AM
    Is anyone aware of an online browser app to obtain a DBML schema from a prisma schema? Ideally, I'd like to paste in my prisma schema and the web app transforms it to DBML
    ✅ 2
    r
    • 2
    • 5
  • r

    Reuben Porter

    08/24/2022, 11:51 AM
    Hi all, I have a question relating to Postgres and JSON fields within Prisma. I have a model which contains a JSON field. I understand Prisma doesn't support custom JSON types on fields yet (only for Mongo). Whats the best practice for ensuring type safety and fixing TS errors when I have to say create a resource?
    ✅ 1
    n
    • 2
    • 1
  • i

    Italo Gama

    08/24/2022, 1:12 PM
    Hey i’ve a question of relational fields. i have users and address table, they are related. they both have FK and when i create a new user, i create the address, and works just fine BUT, i discover that the address on the address table isnt filling the field “user_id” with the ID from the user
  • i

    Italo Gama

    08/24/2022, 1:14 PM
    this is me schema.prisma
  • i

    Italo Gama

    08/24/2022, 1:16 PM
    This is my service
  • i

    Italo Gama

    08/24/2022, 1:16 PM
    What i’m doing wrong?
    ✅ 1
    n
    • 2
    • 19
  • l

    Logan

    08/24/2022, 1:19 PM
    Is there an option when doing queries which says if the
    where: {key: value}
    value is undefined, or null it wont find anything? Currently the following query will count all documents if the input is
    null
    or
    undefined
    and it also works the same was for
    findFirst
    .
    Copy code
    const entriesCount = await client.prisma.giveawayEntry.count({
        where: {
          giveawayId: findGiveaway?.id,
        },
      });
    ✅ 1
    n
    • 2
    • 2
  • h

    Hayley Dawson

    08/24/2022, 5:12 PM
    Question for folks. I am using express-graphql and prisma, and trying to store a JsonObject input. using the GraphQLJsonObject from the graphql-scalars library gives me a very odd error out of prisma validation. What type should I be using/delaring to take JSON input and give it to prisma? Oddly everything works great on output
  • r

    Ray Tiley

    08/24/2022, 5:24 PM
    can anyone point me at an example of doing a one to one and a one to many relation to the same model
  • r

    Ray Tiley

    08/24/2022, 5:25 PM
    the use case is i'm trying to do a revision history where a simple model points to the current version as a one to one but also has a one to many of all the revisions
    👀 1
    ✅ 1
    r
    n
    • 3
    • 12
  • h

    Hayley Dawson

    08/24/2022, 5:50 PM
    So, does Prisma even have a json type it will take as input?
  • h

    Hayley Dawson

    08/24/2022, 5:50 PM
    i see the docs on reading values and writing them but i keep getting validation errors no matter what
    ✅ 1
    a
    • 2
    • 24
  • b

    Boo

    08/24/2022, 7:18 PM
    How do you type cast in Prisma? If i want a field to either be string or bigint?
    👀 1
    ✅ 1
    a
    • 2
    • 4
  • v

    Vanessa Kroeker

    08/24/2022, 8:00 PM
    I'm having an issue running migrations in production as part of our CD pipeline. Deploying on Google Cloud Platform to GKE (so, w/ Dockerfile) and running the migration in an entrypoint script. The migration engine keeps exiting with an error:
    Copy code
    Prisma schema loaded from prisma/schema.prisma
    Datasource "db": PostgreSQL database "dbname", schema "public" at "localhost:5432"
    Error: Migration engine exited.
    So I have also added
    prisma version
    , and get the error that migration-engine binary is not found. (will post full out put of in comment to follow)
    👀 1
    ✅ 1
    a
    • 2
    • 13
  • n

    nick

    08/24/2022, 9:01 PM
    so why axiom?
  • n

    nick

    08/24/2022, 9:01 PM
    i am trying to choose between axiom and datadog
  • n

    nick

    08/24/2022, 9:01 PM
    why use axiom over datadog?
    👀 1
    n
    • 2
    • 1
  • z

    Zac Zajdel

    08/25/2022, 3:13 AM
    Hi everyone! Love using Prisma so far but I seem to have come across a problem that from a lot of searching online appears to be a severe limitation to Prisma. For example, let's say I want to update a model called Jot where I want to check an id and a userId column to verify both the id I am sending from the front-end and the user who is trying to update said model belongs to them like this:
    const deletedJot = await prisma.jot.update({
    where: {
    id: jot.id,
    userId: session.user.id,
    },
    data: {
    deletedAt: new Date(),
    },
    })
    ^ This will not work currently in prisma because you can only use where on unique fields when using
    .update()
    . Now I realize I can use
    .updateMany()
    but that won't return the model for obvious reasons so if I wanna send back the updated model, I now have to make an additional query to grab that which seems unnecessary. Is this in the roadmap to NOT enforce only unique fields for a multiple where condition? It seems like a lot of people online have ran into this same thing and adopting Prisma so early on and finding such a hard blocker makes me question using it even though I find so many amazing things this ORM can do and the innovation this team is doing for the ecosystem and leading the industry in an amazing direction. Thanks for reading my rant everyone 😄
    ✅ 1
    n
    • 2
    • 2
  • b

    Benjamin FROLICHER

    08/25/2022, 5:23 AM
    Hello, How can i find objects that contains a given string in an array with case insensitive ?
    Copy code
    const apps = await this.prisma.app.findMany({
        where : {
            OR: [
                { name : { contains: search, mode: 'insensitive' }},
                    { tags : {
                        hasSome: search // <---- unable to set insensitive search mode. 
                    }}
            ]
        }
    })
    I have found a related feature request https://github.com/prisma/prisma/issues/8387 Do you have a solution while waiting for official support ?
    ✅ 1
    n
    • 2
    • 1
1...612613614...637Latest