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

    Zhen

    02/27/2022, 8:16 PM
    I am deploying to production soon and I wanted to know if there was a way to avoid storing my db credentials in ENV for prisma. Most best practice docs for lambda says to pull from SSM at runtime, rather than using ENV because if you want to inject it into env, then it will probably be in your cloudformation stack. Any advice?
  • h

    Henri Kuper

    02/28/2022, 11:14 AM
    Hi everyone, Is there a way to reset the PrismaClient when the following error occurs?
    Copy code
    "code":"P2024","clientVersion":"3.6.0","meta":{"connection_limit":5,"timeout":10}
    Because currently the client does not recover from this kind of error and I need to restart the whole server manually. Would be a huge win already if I could simply catch the error and “restart/reset” only the prismaClient. Thanks in advance
    👀 1
    n
    • 2
    • 2
  • s

    Stian Bakken

    02/28/2022, 2:40 PM
    Hey everyone, I have a silly issue that I can't seem to figure out in regards to my Schema. I'm trying to model a Match, where two teams go up against eachother. A match can only ever have two teams, so I thought something like this might make sense, but it gives me an error
    Copy code
    model Match {
      id         String    @id @default(uuid())
    
      teamA Team @relation(name: "teamA", fields: [teamAId], references: [id])
      teamB Team @relation(name: "teamB", fields: [teamBId], references: [id])
    
      teamAId String @unique
      teamBId String @unique
    }
    
    model Team {
      id String @id @default(uuid())
    
      match   Match   @relation(fields: [matchId], references: [id])
      matchId String
    }
    If anyone has any better ways to model this or any ideas about how to solve it, I'd really appreciate it 🙂
    n
    • 2
    • 7
  • j

    Juan Orellana

    02/28/2022, 3:23 PM
    is there a way to use if conditions inside a query? for example:
    Copy code
    return this.prisma.user.findMany({
          where: {
            AND: [
    if (searchUserDto.dni) { dni: { contains: searchUserDto.dni } },
    if (searchUserDto.name) { name: { contains: searchUserDto.name} },
    if (searchUserDto.surname) { surname: { contains: searchUserDto.surname} },
    if (searchUserDto.email) { email: { contains: searchUserDto.email } },
    if (searchUserDto.status) { status: { equals: searchUserDto.status.toString() != 'true' ? false : true } },
    if (searchUserDto.bas_role_id) { bas_role_id: { equals: (searchUserDto.bas_role_id) } }
            ]
          }
        });
    🙌 1
    e
    n
    • 3
    • 4
  • j

    Jonas Rothmann

    02/28/2022, 5:28 PM
    I keep getting null/empty strings at the top of my orderBy queries, how can i solve this?
    • 1
    • 1
  • p

    Patrick

    02/28/2022, 6:30 PM
    Hey y’all, I have question about Prisma client being cached on Heroku: I did migration locally and run build on Heroku. App was built and then, in release tasks, migration was applied. Then, I modified my code to use newly added field and run build again. But then build failed - Heroku used cached Prisma client, and TypeScript raised error saying that field does not exist. I solved that by setting NODE_MODULES_CACHE=false, but I would prefer to cache my node modules, so the app builds faster. Is there something I can do?
    a
    • 2
    • 7
  • m

    Matt Mueller (Prisma Client PM)

    02/28/2022, 10:39 PM
    Hey all, I just wanted to share that Embedded Document support for MongoDB is now in Preview! It's easy to get started. First, install the latest Prisma (3.10.0) and add the
    mongoDb
    preview feature flag:
    Copy code
    prisma
    datasource db {
      provider = "mongodb"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["mongoDb"]
    }
    Then you'll have a new
    type
    keyword in your Prisma Schema, for example:
    Copy code
    prisma
    model Order {
      id              String   @id @default(auto()) @map("_id") @db.ObjectId
      product         Product  @relation(fields: [productId], references: [id])
      color           Color
      size            Size
      shippingAddress Address
      billingAddress  Address?
      productId       String   @db.ObjectId
    }
    
    // New composite type!
    type Address {
      street String
      city   String
      zip    String
    }
    Once you run
    prisma generate
    , you'll have a new type-safe API for working with these types. For example, here's how you'd create a new Order with an embedded shipping address:
    Copy code
    ts
    const order = await prisma.order.create({
      data: {
        // Normal relation
        product: { connect: { id: 'some-object-id' } },
        color: 'Red',
        size: 'Large',
        // Composite type
        shippingAddress: {
          street: '1084 Candycane Lane',
          city: 'Silverlake',
          zip: '84323',
        },
      },
    })
    This is just the tip of the iceberg. Dive deeper in our documentation. --- If you have any feedback for us, I'd love to jump on a call with you. We're actively working towards getting MongoDB production ready, so now's the time to give this a try and share your thoughts!
    prisma rainbow 2
    mongodb 2
    prisma cool 1
  • m

    mxstbr

    03/01/2022, 7:50 AM
    Question: I just got this PR to bedrock.mxstbr.com — is
    //
    the correct form of comments in the
    schema.prisma
    file?
    d
    c
    • 3
    • 3
  • a

    Adrian

    03/01/2022, 9:36 AM
    Is it problematic for anyone else that the Prisma types have null values for optional keys? I find it utterly annoying to add values as null to my variables when the value is clearly undefined
    a
    • 2
    • 1
  • a

    Adrian

    03/01/2022, 9:39 AM
    I wonder if someone found a Typescript way to may prisma types have use optional properties instead of null values
  • g

    Geebrox

    03/01/2022, 10:48 AM
    Hello, I am getting this error when trying to generate:
    Copy code
    error: Property not known: "activeProvider".
    -->  schema.prisma:4
    |
    3 |   provider       = "mongodb"
    4 |   activeProvider = "mongodb"
    5 |   url            = env("DATABASE_URL")
    |
    n
    s
    • 3
    • 4
  • z

    Zefex Developer

    03/01/2022, 12:52 PM
    Hi there, I'm following the many-to-many tutorial and I tweaked that to "tags" and I'm wondering, how can I get all tags associated with a user? I did like this but I'm not sure if that is the best way:
    Copy code
    const tags = await prisma.tag.findMany({
          where: {
            users: {
              every: {
                user: {
                  id
                }
              }
            }
          }
        })
    a
    • 2
    • 2
  • m

    Michael Stewart

    03/01/2022, 1:36 PM
    Hi people, where can I look for help regarding
    serverless-plugin-typescript
    ? 🙂
  • u

    Utsav Shah

    03/01/2022, 4:53 PM
    hi all, do we have a rough idea of the answer for https://github.com/prisma/prisma/discussions/9002? it's the only blocker for our company from picking prisma over others.
    a
    • 2
    • 1
  • a

    aj

    03/01/2022, 7:18 PM
    hi, I have user and order tables. Order table has orderNumber column, not unique. orderNumber must increment by one for each user. How do I implement this? Auto increment won’t work in this scenario as it increments by the total count in the table. Thanks!
    n
    • 2
    • 2
  • z

    Zefex Developer

    03/02/2022, 12:03 AM
    How can I update a user with a certain id connecting to an existing tag in a many-to-many relationship? https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations
    Copy code
    prisma.user.update({
        where: { id: '' },
        data: {
          name: 'John Doe',
          tags: {
            connect: {
              tagId_userId: {
                tagId: '',
                userId: ''
              }
            }
          }
        }
      })
    I didn't want to repeat the
    userId
    especially because I'm going to be asking as an input for the user. Is there another way of doing that? In resume, is there a way to only specify the tag ids instead of the
    userId
    over and over again?
    c
    • 2
    • 2
  • d

    David

    03/02/2022, 3:02 AM
    hi all, did Prisma change their migration naming formula? I notice some new migration having different naming format now, before is YYYY MM DD now is YYYY DD MM. 😄
    ⁉️ 4
    n
    j
    c
    • 4
    • 5
  • d

    Deepak Guptha S

    03/02/2022, 8:57 AM
    Hello, How to perform DateDiff - SQL functions in Prisma ? I could not find the docs related to it 😞 For Example: I have a query
    Copy code
    SELECT *
    FROM employees
    WHERE DATEDIFF(hire_date, STR_TO_DATE('2021-01-01', '%Y-%m-%d')) >= 0
    Anyone has the solution for it ?
    h
    • 2
    • 3
  • p

    Peter Takacs

    03/02/2022, 2:41 PM
    Guys, I am really struggling at my prisma server. I have migrated lately from 1.34 to 3.1 and my queries extremly slowed down compared to the previous version. I have tested at local development for a dataset of 1000 records. And debugged the resolver, and the resolver provides the dataset under 1 second, and returns it from the function. But then at the client side its pending ( at the network tab) for about 27 sec more. I have tested at the playground also with a similar query as the client has, but there is the same amount of 27 sec waiting until the data provided. It should not network related since the resolver provide the dataset quite fast, under 1 sec. And it has also not client related since playground also suffer from this long wait time to display the result, after the data resolved. I am using apollo-server-express “^3.5.0” and “nexus”: “^1.1.0”, “@prisma/client”: “^3.10.0”, I really does not have any idea where to go from here. Advices appreciated. Many thanks UPDATE Probably It caused by the nested queries, since i just tested the main query return time! But still it is a significant performance loss compared to v1.34, which resulted the final result approx 8-10x faster for the same query. Is it possible to debug the nested calls?
    c
    n
    • 3
    • 2
  • v

    Vignesh T.V.

    03/02/2022, 5:00 PM
    Hi. Just had a quick question. Let's say I establish a unique relation like this combining multiple fields and I call the combined field name as `key`:
    @@unique([field1, field2], name: "key")
    Now, is it possible to relate to
    key
    from other models like
    @relation(fields: [field3], references: [key])
    Currently it says that I can only map to fields that exist if I do this
    j
    • 2
    • 3
  • j

    Johnson Detlev

    03/02/2022, 6:20 PM
    Hey everybody, I have a question where I can't really wrap my head around how to best model it. I have a Thread model and I have a Feed, Group and Project model. The User, Group and Project model all can have multiple threads attached, but the Thread model can only have a Feed attached OR a Group OR a Project. How would I model this in prisma? Do I just write all model relations on the Thread model as optional?
  • m

    Moe Green

    03/02/2022, 6:23 PM
    guys, how can I write such request -
    SELECT * FROM users WHERE email = '<mailto:ccc@gmail.com|ccc@gmail.com>' AND username = 'ccc'
    in Prisma?
    j
    m
    • 3
    • 4
  • j

    Juan Orellana

    03/02/2022, 8:08 PM
    Hi there hope you all are ok, Anyone knows whats the best aproach to select by date?, I mean I want to get all entries on my mysql DB that have on date column date for example '2022-03-02' , take in mind that date is dynamic. also this date is going to be used from query params, so I want to avoid if a user writes manually on web address anything else that is not in (YYYY-MM-DD) format then dont apply that filter. These kinds of filters are pretty hard to understand at least for me, is not like on string columns that we can use contains, startswith, endswith. But on anything else that I can't find a way without using rawquery
    m
    • 2
    • 1
  • d

    Damian M

    03/03/2022, 4:02 AM
    is it possible orderBy a string but make it case insensitive?
    n
    • 2
    • 2
  • f

    Fauziya Shaikh

    03/03/2022, 7:18 AM
    Hi all. I am Fauziya and I am using prisma + nestjs + docker on MAC M1 chip and have issues installing and accessing the openssl binary. Any help or direction is greatly appreciated. This is the latest error log -
    > npx prisma generate
    #30 0.243
    #30 4.198 Prisma schema loaded from prisma/schema.prisma
    #30 4.352 Error: Get config: Error: Command failed with ENOENT: /usr/local/lib/node_modules/prisma/query-engine-linux-arm-openssl-1.1.x cli get-config --ignoreEnvVarErrors
    #30 4.352 spawn /usr/local/lib/node_modules/prisma/query-engine-linux-arm-openssl-1.1.x ENOENT
    n
    • 2
    • 1
  • k

    Kapil Sharma

    03/03/2022, 8:33 AM
    Hi folks, we have Managed Azure SQL DB and we are trying to connect to it using Prisma Client in a NodeJS app. We followed the docs to create DATABASE_URL but it keeps throwing:
    Error: Error in connector: Authentication failed for user 'myuser'
    Our connection string is created like:
    DATABSE_URL="<sqlserver://HOST>:PORT;database=DB_NAME;username=DB_USER;password=DB_PASSWORD;integratedSecurity=true;trustServerCertificate=true"
    Has anyone tried connecting to Azure SQL server using Azure Active Directory Password authentication in Prisma?
    a
    • 2
    • 3
  • k

    Kapil Sharma

    03/03/2022, 8:36 AM
    In sequelize, we can pass
    options: {dialect, authentication: {type: 'azure-active-directory-password'}}
    . Is it even feasible in Prisma?
  • s

    shahrukh ahmed

    03/03/2022, 12:55 PM
    Has anyone used Prisma Studio in production like an admin?
    s
    • 2
    • 1
  • e

    ezeikel

    03/03/2022, 3:25 PM
    Hey all 👋🏿 I have two questions 🙋🏿‍♂️ 1. Is there a way to use field count
    _.count: { select: {...} }
    with a filter like you can in
    prisma.x.count()
    ? this is to allow ignoring records marked as deleted in the count for example 2. Has anyone else experienced an issue with using field count in combination with a filter on a relation in
    findMany
    e.g. get me all of the posts for a specific user but also but also give me a count of
    x
    field? - this causes a really slow query for me averaging about 25s and removing the user filter OR the
    _.count
    gets the time taken back down to ~1s? (using mongo connecter btw)
    t
    • 2
    • 3
  • c

    Casey Chow

    03/03/2022, 11:29 PM
    Anyone see this error lately?
    Copy code
    Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: FromSql(6), cause: Some(WasNull) }) })
    j
    • 2
    • 3
1...550551552...637Latest