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

    Taylor Lindores-Reeves

    09/05/2022, 12:25 PM
    One minute
    ✅ 1
    r
    • 2
    • 3
  • k

    Kay Khan

    09/05/2022, 1:54 PM
    Just saw npx prisma introspection has been changed to npx prisma db pull --force since when?
    ✅ 2
    r
    • 2
    • 2
  • k

    Kay Khan

    09/05/2022, 3:19 PM
    Does anyone know how to change the location of the generated prisma client for example
    Copy code
    core/
    lambda/
    within lambda folder.
    Copy code
    npx prisma generate --schema ../core/prisma/schema.prisma
    Copy code
    ✔ Generated Prisma Client (4.3.1 | library) to ./../core/node_modules/@prisma/client in 162ms
    You can now start using Prisma Client in your code. Reference: <https://pris.ly/d/client>
    It installed within the
    ./../core/node_modules/@prisma/client in 162ms
    how do i isntall the prisma client to the current lambda folder node_modues e,g
    node_modules/
    👀 1
    s
    k
    • 3
    • 27
  • y

    Yuval Datner

    09/05/2022, 3:19 PM
    Hey, I'm building a product and using postgres. Performance is paramount to the experience of what I am building, and I've read somewhere that prisma does a query-per-depth kind of situation. This isn't usually an issue, but I have a pretty deeply nested query that is required. Is there a way to optimize prisma queries?
    ✅ 1
    r
    • 2
    • 1
  • j

    Jaskaran Yadav

    09/05/2022, 5:15 PM
    hlo
  • j

    Jaskaran Yadav

    09/05/2022, 5:17 PM
    i am facing an issue in prisma. if my row size is greater then 32766 it gives error
    ✅ 1
    r
    • 2
    • 2
  • s

    s s

    09/05/2022, 6:04 PM
    Anyone encountered this before? (Vercel)
    ✅ 1
    s
    • 2
    • 14
  • r

    Rexford Koomson

    09/05/2022, 7:46 PM
    👋 Hello, team!
    👋 4
    n
    • 2
    • 1
  • j

    Jason Marmon

    09/06/2022, 3:09 AM
    Howdy Prisma people - because the fulltext client doesn’t currently support setting the language in queries (e.g. ‘english’ in
    to_tsvector('english', body) @@ to_tsquery('english', 'friend');
    ) , I want to set the default postgres setting
    default_text_search_config
    globally. I’m currently working around this via a migration which does:
    Copy code
    ALTER SYSTEM SET default_text_search_config TO 'simple';
    But another way to do this is per connection, e.g
    SET default_text_search_config = 'simple'
    , but since this setting exists per connection I need to run it every time a connection is created. is there any reasonable way to run an
    $executeRaw
    for each new pg connection?
    ✅ 1
    h
    • 2
    • 2
  • j

    Jaskaran Yadav

    09/06/2022, 3:19 AM
    Hello team I am having an error in prisma . if my row count is greater then 32766 it gives error “ Can't reach database server”. Working fine when row count is below 32767
    s
    v
    • 3
    • 29
  • k

    Kay Khan

    09/06/2022, 8:54 AM
    Anyone who works with serverless framework and uses typescript serverless.ts know how to associate a layer with your function? Im getting some typescript error with this.
    Copy code
    functions: {
            main: {
                handler: "handler.MainHandler",
                timeout: 300,
                layers: {
                    Ref: "PrismaLambdaLayer",
                },
            },
        },
    Copy code
    Type '{ Ref: string; }' is not assignable to type 'AwsLambdaLayers'.
         Object literal may only specify known properties, and 'Ref' does not exist in type 'AwsArn[]'.
    ✅ 1
    h
    • 2
    • 2
  • ø

    Ørjan

    09/06/2022, 9:00 AM
    Hi, to connect the user correctly you would need to replace String? with a reference to the User model like this:
    Copy code
    model Shipment {
      createdBy        User? @relation("CreatedShipments", fields: [createdById], references: [id])
      createdById.     String?
      lastUpdatedBy    User? @relation("UpdatedShipments", fields: [lastUpdatedById], references: [id])
      lastUpdatedById  String?
    }
    Since you have two references to user, you will need to define different names for each of them you should also add the same names to the relations on the User side:
    Copy code
    model User {
      createdShipments Shipment[] @relation("CreatedShipments")
      updatedShipments Shipment[] @relation("UpdatedShipments")
    }
    It is also necessary to define which field from user you want to reference by. In this case we use the ID from user and store it inside createdById and lastUpdatedById. For question 2, createdAt will only use now() to store the date of the creation, and will not be updated later. for updatedAt you should use the @updatedAt attribute, and Prisma will automatically update the time for you:
    Copy code
    updatedAt  DateTime @updatedAt
    (docs: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#updatedat)
    r
    • 2
    • 1
  • s

    Seb Powell

    09/06/2022, 10:57 AM
    Hi there – having an issue with doing bulk inserts, and hoping someone might be able to point out what I'm doing wrong
    👀 1
    h
    • 2
    • 43
  • s

    Seb Powell

    09/06/2022, 10:58 AM
    https://github.com/prisma/prisma/issues/8131#issuecomment-1237992626
  • m

    Mattia

    09/06/2022, 11:41 AM
    Hi, guys. Quick question. my schema is using
    @db.Timestamp(6)
    , but
    prisma.table.findMany()
    is auto parsed to JS Date, is any way to return string only?
    ✅ 1
    h
    v
    • 3
    • 6
  • k

    Kay Khan

    09/06/2022, 4:00 PM
    Hi if anyone has time please take a look at my example minimal reproduction app which attempts to use prisma as a layer in typescript aws serverless function https://github.com/kaykhan/prisma-typescript-example I am getting the following error: ✖️ Error: ENOENT: no such file or directory, open '/home/kay/kay/prisma-example-typescript/app1/.esbuild/.build/schema.prisma' Attempting to follow this guide: https://dev.to/sabinthedev/managing-lambda-size-with-multiple-prisma-clients-4m8l
    👀 1
    a
    s
    • 3
    • 3
  • k

    Kyle Oliveiro

    09/06/2022, 5:26 PM
    hi guys, how can i get a random record from a postgres table using prisma? currently im getting all records using
    prisma.Collection.findMany
    , then manually retrieving a random record from there using
    Math.random
    . this works, but my app is starting to grow and this function is now crashing in production presumably because i have too much data and the server is running out of memory trying to query everything at once
    ✅ 1
    k
    • 2
    • 2
  • t

    Ted Joe

    09/06/2022, 6:21 PM
    I have a
    firstName
    and
    lastName
    columns in my postgres db. How can I order by
    firstName + lastName
    using prisma?
    ✅ 2
    r
    • 2
    • 4
  • o

    Oscar Mejia

    09/06/2022, 9:03 PM
    Hi all, Cascading Deletes aren't working in one of my relationships. I'm confused. This is what my schema looks like:
    Copy code
    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["interactiveTransactions", "referentialIntegrity"]
    }
    
    // process.env.production 
    
    datasource db {
      provider             = "postgresql"
      url                  = env("DATABASE_URL")
      referentialIntegrity = "prisma"
    }
    
    enum MANAGER_TYPE {
      ADMIN
      KITCHEN_MANAGER
    }
    
    model User {
      id           String       @id @default(cuid())
      createdAt    DateTime     @default(now())
      updatedAt    DateTime     @updatedAt
      email        String?      @unique
      type         MANAGER_TYPE @default(KITCHEN_MANAGER)
      Restaurant   Restaurant?  @relation(fields: [restaurantId], references: [id])
      restaurantId String?
      User         Order[]
    }
    
    model Restaurant {
      id                          String          @id @default(cuid())
      name                        String
      KMInventoryLastUpdatedAt    DateTime?
      adminInventoryLastUpdatedAt DateTime?
      item                        Item[]
      inventoryItems              InventoryItem[]
      user                        User[]
      orders                      Order[]
    }
    
    model Item {
      id                 String          @id @default(cuid())
      createdAt          DateTime        @default(now())
      name               String
      par                Float
      unit               Unit[]
      amtOnHand          Float?
      Restaurant         Restaurant      @relation(fields: [restaurantId], references: [id])
      restaurantId       String
      itemsOnOrder       ItemsOnOrders[]
      refInventoryItemId String?
    }
    
    model Unit {
      id                 String          @id @default(cuid())
      updatedAt          DateTime        @updatedAt
      name               String
      price              Float
      default            Boolean
      Item               Item            @relation(fields: [itemId], references: [id], onDelete: Cascade)
      itemId             String
      itemsOnOrders      ItemsOnOrders[]
      refInventoryUnitId String?
    }
    
    model InventoryItem {
      id            String          @id @default(cuid())
      createdAt     DateTime        @default(now())
      updatedAt     DateTime        @updatedAt
      name          String
      par           Float
      inventoryUnit InventoryUnit[]
      amtOnHand     Float?
      Restaurant    Restaurant      @relation(fields: [restaurantId], references: [id])
      restaurantId  String
    }
    
    model InventoryUnit {
      id              String        @id @default(cuid())
      updatedAt       DateTime      @updatedAt
      name            String
      price           Float
      default         Boolean
      InventoryItem   InventoryItem @relation(fields: [inventoryItemId], references: [id], onDelete: Cascade)
      inventoryItemId String
    }
    
    model ItemsOnOrders {
      Item       Item   @relation(fields: [itemId], references: [id], onDelete: Cascade)
      itemId     String
      Order      Order  @relation(fields: [orderId], references: [id], onDelete: Cascade)
      orderId    Int
      amtToOrder Float
      Unit       Unit   @relation(fields: [unitId], references: [id]) // Unit used in Order
      unitId     String
    
      @@id([itemId, orderId])
    }
    
    enum Status {
      ACTIVE
      FULLFILLED
    }
    
    model Order {
      id           Int             @id @default(autoincrement())
      createdAt    DateTime        @default(now())
      updatedAt    DateTime        @updatedAt
      User         User            @relation(fields: [userId], references: [id])
      userId       String
      notes        String
      itemsOnOrder ItemsOnOrders[]
      Restaurant   Restaurant      @relation(fields: [restaurantId], references: [id])
      restaurantId String
      status       Status          @default(ACTIVE)
    }
    I want it so when user deletes an Order -> related ItemsOnOrders is deleted -> Items in Order are deleted -> The Units of the those Items are deleted. Right now, when I delete an Order -> related ItemsOnOrders is deleted, but the Items and Units remain. I also want to note that when I delete the ItemsOnOrders record manually from prisma studio, the Items remain even though I have it marked to cascade delete in the model ItemsOnOrders
    Copy code
    Item       Item   @relation(fields: [itemId], references: [id], onDelete: Cascade)
    Help is much appreciated 🙏
    j
    v
    • 3
    • 2
  • c

    Clément Guibout

    09/06/2022, 10:05 PM
    Hey guys I need to query my database one time to get a list of object For each one of these objects, I need to add one field that requires another query to the database The solution I currently have is I first get the list, and then map the result to itself and I add a new field by querying n time the database again, but this is quite slow Is thery a way to add a custom fields that does another request in the first one? Thank you
    ✅ 1
    n
    v
    • 3
    • 5
  • b

    Bryan Z

    09/07/2022, 5:11 AM
    Hi everyone, I'm following the

    Next.js GraphQL API using Apollo Server 3 and Prisma▾

    tutorial but when I call
    links: async (context: Context) => await context.prisma.link.findMany()
    in
    resolvers.ts
    I get the error
    "Cannot read properties of undefined (reading 'prisma')"
    when making a query in Apollo studio. However, not using context and calling
    links: async () => prisma.link.findMany(),
    returns the data as expected. Is there something wrong in my
    context.ts
    file? Here are the contents and thanks for your help!
    Copy code
    import type { NextApiRequest, NextApiResponse } from 'next'
    import { PrismaClient } from '@prisma/client'
    import prisma from '../src/server/db/client'
    
    export type Context = {
      prisma: PrismaClient
    }
    
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    export async function createContext(
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      req: NextApiRequest,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      res: NextApiResponse
    ): Promise<Context> {
      return {
        prisma,
      }
    }
    👀 1
    a
    • 2
    • 4
  • h

    hoeJ K

    09/07/2022, 5:24 AM
    Hello everyone. I am trying to findMany RequestPost table in cursor pagination method. But the problem is I don’t know how to orderBy using the (LIKE count - DISLIKE count) value in the type of requestReactions. I am using mysql. please help me…
    Copy code
    /// schema.prisma
    model RequestReaction {
      id        BigInt      @id @default(autoincrement()) @db.BigInt
      request   RequestPost @relation(fields: [requestId], references: [id], onDelete: Cascade)  
      requestId BigInt
      user      User?        @relation(fields: [userId], references: [id], onDelete: SetNull)
      userId    String?
      type      RequestReactionType
      createdAt DateTime    @default(now())
    
      @@index([requestId, userId, type, createdAt(sort: Desc)])
      @@map("requestreactions")
    }
    enum RequestReactionType {
      LIKE
      DISLIKE
    }
    
    model RequestPost {
      id            BigInt        @id @default(autoincrement()) @db.BigInt
      createdAt     DateTime      @default(now())
      updatedAt     DateTime      @updatedAt
      user          User?         @relation(fields: [userId], references: [id], onDelete: SetNull)
      userId        String?
      title         String        @db.VarChar(255)
      content       String        @db.LongText
      category      RequestCategoryType?        @default(ETC)
      creator       Creator?      @relation(fields: [creatorId], references: [id], onDelete: SetNull)
      creatorId     BigInt?
      expires       DateTime?
      totalViews    Int           @default(0)
      status        RequestStatusType   @default(REQUEST)
      solvedUrl     String?
      refusalReason String?
      requestApplyCreators RequestApplyCreator[]
      requestPlatforms     RequestPlatform[]  
      requestFundings      RequestFunding[]
      requestComments      RequestComment[]
      requestReactions     RequestReaction[]
      requestBookmarks     RequestBookmark[]
      requestReports       RequestReport[]
      requestInquirys      RequestInquiry[]
    
      @@index([userId, creatorId, status, createdAt(sort: Desc)])
      @@fulltext([title, content])
      @@map("requestposts")
    }
    
    // ...
    
    
    //// client.ts
    prisma.requestPost.findMany({
        where: {
          userId,
        },
        orderBy: [
          // What should I do?
        ],
        cursor: {
          id: lastId,
        },
        take: 5,
        skip: lastId ? 1 : 0,
    
        include: {
          requestComments: true,
          requestApplyCreators: true,
          requestFundings: true,
          requestPlatforms: true,
          requestReactions: true,
        },
      });
    👀 1
    a
    v
    • 3
    • 2
  • z

    Zahra Mumtaz

    09/07/2022, 8:25 AM
    Hi @all, II am trying to search if a value exist in array using nest.js with prisma using following query
    Copy code
    return await this.prisma.permission.findFirst(({ 
                where: { systemPermissions: { contains : permission } 
            } }))
    Here systemPermission is an array of string. e.g: [“abc”, “Def”, “ghi”] But it’s not working for me. Any help?
    👀 1
    r
    v
    • 3
    • 3
  • h

    Harry Lee

    09/07/2022, 8:36 AM
    Hi all, would there be any best practices for implementation of SELECT FOR UPDATE? I’m trying to lock a specific row exclusively, but it doesn’t seem to work Here is my example
    Copy code
    const rawQuery: Prisma.Sql = Prisma.sql`
      SELECT "balance".id,
             "balance".user_id,
             "balance".balance,
             "balance".created_at,
             "balance".updated_at
      FROM "balance" 
      WHERE "balance".user_id = ${Number(input.userId)} 
      FOR UPDATE NOWAIT
      `;
    
      const balances = await _prismaService.$queryRaw<BalanceModel[]>(rawQuery);
    ✅ 1
    a
    v
    • 3
    • 4
  • z

    Zahra Mumtaz

    09/07/2022, 8:51 AM
    Exactly facing error mentioned in liink: https://github.com/MichalLytek/typegraphql-prisma/issues/84 Regretfully it’s unanswered
    👀 1
    a
    v
    • 3
    • 4
  • j

    janpio

    09/07/2022, 10:49 AM
    Hey, Engineering at Prisma prisma dark here. I have question where you could hopefully help me out: We want to understand what you are using the
    binaryTargets
    property of the Prisma Client
    generator
    for. (It is documented here: https://www.prisma.io/docs/concepts/components/prisma-schema/generators#binary-targets + https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#fields-1 + https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#binarytargets-options) If you use
    binaryTargets
    in your project, please let me know why you are using it, where you deploy to etc in this thread. Thanks!
    prisma rainbow 1
  • t

    Ted Joe

    09/07/2022, 2:54 PM
    When using
    db.$queryRaw
    , I'm trying to
    ORDER BY
    a variable, so something like this: `await db.$queryRaw`SELECT * FROM "User" ORDER BY ${order}`` But the order doesn't seem to have any effect. is there another way to do it?
    👀 1
    j
    r
    v
    • 4
    • 6
  • t

    Ted Joe

    09/07/2022, 3:19 PM
    Then when I add
    ${orderBy}
    i.e. whether it's desc or asc, it throws an error...
  • o

    Omar

    09/07/2022, 4:19 PM
    Guys, can I get your ideas on this? https://github.com/prisma/prisma/issues/3528#issuecomment-1239600050 I wrote a little suggestion on how to do validations with Prisma. If you have any ideas or suggestions, please share them on that issue.
    👀 1
    ✅ 1
    n
    a
    • 3
    • 4
  • m

    May

    09/07/2022, 4:23 PM
    Hi, Please can any one please help me with this I am having some challenges working with prisma and AWS SAM for local tests on an AWS API Gateway infrastructure it returns this error
    ENOENT: no such file or directory, open '/var/task/schema.prisma
    but i am not sure why as my unit tests are passing and I can communicate with the DB via prisma. For context, the project is bundled using Babel and infrastructure was created with AWS CDK
    ✅ 1
    k
    • 2
    • 2
1...617618619...637Latest