https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# prisma-client
  • d

    David A. Black

    12/24/2021, 9:39 AM
    Good morning. I’m pretty new to Prisma, and i’ve hit the “unable to be run in the browser thing” — and that makes sense to me. but one odd (to me) thing. I have a
    lib/utils.js
    file that uses prisma client, and utils are used in a
    getServerSideProps
    . I’m doing the global prisma client technique. But I have to import prisma in the page, not the utils file. And I get the browser-running error unless I simply refer to
    prisma
    in the
    getServerSideProps
    . So I literally have a line that looks like:
    var thisPreventsThePrismaClientError = prisma
  • d

    David A. Black

    12/24/2021, 9:40 AM
    Code available of course but i’m wondering if this rings any bells for anyone
  • m

    Mischa

    12/28/2021, 8:26 AM
    is there any way to change how the nodejs generated client is built? for example I’d like to build it without minification so I can better profile my cold starts
  • m

    Mischa

    12/28/2021, 10:18 AM
    I really need to get my lambda cold start time with prisma down. I am trying to provide as much data and information about it here if anyone else is interested: https://github.com/prisma/prisma/issues/10724
  • d

    David

    01/03/2022, 10:33 PM
    Any reason
    meta
    is of type object in prisma client? Seems like
    Record<string, unknown>
    would be more appropriate. Personally I'm trying to access
    error.meta.target
    but of course TypeScript isn't happy about that because
    object
    is supposed to be equivalent to
    {}
    and thus even with optional chaining this is still invalid. So far seems like my only options are to PR and ts-ignore/coerce to any, but this is really not ideal... and I wanna make sure this is a mistake before I PR.
    Copy code
    export declare class PrismaClientKnownRequestError extends Error {
        code: string;
        meta?: object;
        clientVersion: string;
        constructor(message: string, code: string, clientVersion: string, meta?: any);
        get [Symbol.toStringTag](): string;
    }
  • t

    Tyler Bell

    01/04/2022, 4:22 AM
    Hi all, trying to figure out the best way to update a single record or create it if it doesn’t exist. My schema is….
    Copy code
    model App {
      id                  String               @id @default(cuid())
      createdAt           DateTime             @default(now())
      updatedAt           DateTime?            @updatedAt
      name                String
    
      redirects Redirects[]
    
      @@index([slug], map: "App.slug_index")
    }
    
    model Redirects {
      id String @id @default(cuid())
    
      global Boolean
    
      afterSignup   String?
      afterLogin    String?
      afterLogout   String?
    
      appId String
      app   App    @relation(fields: [appId], references: [id])
    }
    I want to update a single record that matches an
    appId
    and where
    global
    is
    true
    If a record doesn’t match that, I would like it to be created. Having difficulties doing that tho, since the
    upsert
    method only accepts the
    id
    field in the
    where
    argument. So what’s the best way to do this? The following code is essentially what I’m trying to do.
    Copy code
    prisma.redirects.upsert({
          where: {
            appId,
            global:true
          },
          create: {
            ...redirects,
            app: { connect: { id: appId } },
          },
          update: {
            ...redirects,
            app: { connect: { id: appId } },
          }
        })
    Thanks!
    m
    • 2
    • 3
  • a

    Adrian

    01/07/2022, 8:50 AM
    Hi, I want to want to have an 1:n relationship (
    aThing
    ,
    bThing
    ). But the data comes async over a eventbus. So it can happen, that
    aThing
    trys to reference an ID from
    bThing
    , that is currently not there. How can I describe this in the schema, so that I dont get an `Foreign key constraint failed on the field`error?
  • a

    Aman Tiwari

    01/09/2022, 9:33 PM
    Copy code
    const enquiry = await db.enquiry.findFirst({
        where: { id },
        include: {
          users: {
            include: {
              user: true,
            },
          },
        },
      })
    
      if (!enquiry) throw new NotFoundError()
    
      const partner = enquiry.users.filter((arr) => arr.user.role === "PARTNER")[0]
      const customer = enquiry.users.filter((arr) => arr.user.role === "USER")[0]
    
    return { ...enquiry, partner, customer }
    is this good idea? what are the other way to do?
  • m

    Mischa

    01/11/2022, 11:29 AM
    Trying to figure out how to translate this to prisma with groupBy... can't figure out how to group by the related field or get the average of cvm.match
    Untitled.sql
  • m

    Mischa

    01/11/2022, 11:30 AM
    Copy code
    this.model.groupBy({
          by: ["id"], // <- what goes here?
          _avg: {}, // <- what goes here?
          orderBy: {_avg:{}},// <- what goes here? 
          where: {
            AND: [
              { CandidateVacancyMatch: { every: { isLatest: true } } }, // latest matches
              this.filterForUserRead(user),
            ],
          },
        })
  • o

    Oyewole ABAYOMI S.

    01/13/2022, 1:08 AM
    Please, i need help. Is there a way for prisma groupBy set default value instead of returning empty array
    Copy code
    const i = await this.prisma.transactions.groupBy({
          by: ['status'],
          where: {
            status: { in: ['APPROVED', 'COMPLETED', 'PENDING'] }
          },
          _count: {
            status: true
          }
        })
    console.log(i) // []
    
    // i need something like
    // {approved: 0, pending: 0, completed: 0}
    Thank you.
  • t

    Tom McKenzie

    01/17/2022, 12:07 AM
    is there any information the team can share around Support Tracing in Prisma Client? We (at Mr Yum) would love to assist if possible before investing in hacking our own solution
    • 1
    • 2
  • m

    Mischa

    01/17/2022, 3:46 PM
    What does this error mean?
    Copy code
    /Users/cyber/dev/platform/node_modules/@prisma/client/runtime/index.js:39054
            throw new PrismaClientUnknownRequestError(message, this.client._clientVersion);
                  ^
    PrismaClientUnknownRequestError: 
    Invalid `prisma.candidate.findUnique()` invocation:
    
    
      Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: FromSql(4), cause: Some(WasNull) }) })
        at Object.request (/Users/cyber/dev/platform/node_modules/@prisma/client/runtime/index.js:39054:15)
        at async CandidateRepository.getByIdOr404 (file:///Users/cyber/dev/platform/packages/service/src/repo/repository/base.ts:82:17)
  • k

    KATT

    01/17/2022, 7:40 PM
    hey! is there a way of
    @map
    -ing the relationship tables - for instance i want my
    _OrgToUser
    join table to be
    _org_to_user
    ? i can’t seem to find it in the docs
    n
    • 2
    • 7
  • a

    Alonso A.

    01/18/2022, 4:55 AM
    Hi i am using prisma with express server, i am able to get the data from the prisma client but not able to send it with res.send or res.json.
    j
    • 2
    • 2
  • a

    Alonso A.

    01/18/2022, 4:56 AM
    data.getData() is running prisma client call under the hood, i am able to console.log(response) and see the queried data but when i try to res it, the server response throws error status 500, and when trying to use json it will throw error of not being able to stringify bigInt
  • a

    Alonso A.

    01/18/2022, 4:57 AM
    i tried googling around but haven't been able to get my head around it why it wouldn't work since i am able to console the data returned from the prisma client, any help appreciated
  • a

    Andrew Ross

    01/18/2022, 6:09 AM
    @Alonso A. I've found that apollo-datasource-rest, apollo-datasource-http, or axios works well for handling data-sources with apollo server. you can make blazing fast 3rd party integrations using axios/apollo-datasource-rest. I use both currently and have zendesk calls to their rest endpoint integrated as queries/mutations
    Copy code
    // see <https://www.apollographql.com/docs/tutorial/data-source/>
    import { RequestOptions, RESTDataSource, Request, Response } from "apollo-datasource-rest";
    //...
    export class ZenApi extends RESTDataSource<Request> {
      constructor() {
        super();     
      }
      baseURL = `https://${
          process.env.ZEN_SUBDOMAIN || ""
          }.<http://zendesk.com/api/v2/`;|zendesk.com/api/v2/`;> 
    // do stuff -- get post etc
      async zenPostUserCreateTicket(ticketInput: ZenUserCreateTicketInput) {
        return await <http://this.post|this.post><ZenSyncUserTicketOutput>('tickets', { ticketInput }).then((ticket) => ticket)
      }
    }
    
    // IN THE SERVER FILE
    	const server = new ApolloServer({
    		schema,
            typeDefs,
    		apollo as ApolloConfigInput,
    		playground: isProdEnvironment() === false,
    		dataSources: (): DataSources<object> => {
    			return {
    				zenApi: new ZenApi()
    			}
    		},
    		async context({ req, res }): Promise<Context> { /*return prisma in context*/}
    but first try returning prisma as typeof PrismaClient in your server's context so you can access it in GraphQLContext as well as in RequestContext
    a
    • 2
    • 1
  • s

    sunech

    01/20/2022, 11:07 AM
    Rookie question 👋 Am I misunderstanding something, or is it correct that some relatively simple queries, will end up taking up a lot of "code space" compared to what they would in a direct SQL query? Like if you have a lot of conditions like "X > Y and X < Z and A like '%B%'" and B <> 'C' etc. in a one-line SQL query, it suddenly seems much more comprehensive to build in Prisma. Is this just a compromise that you get used to quickly, as the flexibility and clearer overview ends up trumping the fact that it takes up more space?
  • y

    Yaakov

    01/25/2022, 5:41 PM
    Hi, is there a way to define a one-to-one relation based on 2 fields? I'd like to relate the 
    User
     and 
    InternalUserProfile
     only when 
    User.type = INTERNAL
    .
    Copy code
    model User {
      id                  Int                  @id @default(autoincrement())
      type                UserType
      internalUserProfile InternalUserProfile?
    }
    
    model InternalUserProfile {
      user   User @relation(fields: [userId = User.id AND User.type = 'INTERNAL'], references: [id])
      userId Int
    }
    
    enum UserType {
      INTERNAL
      EXTERNAL
    }
    Thank you!
  • b

    Barnaby

    01/26/2022, 5:49 PM
    How to tell Prisma to use
    -W
    or
    --ignore-workspace-root-check
    ? breaking builds in a monorepo
    error Running this command will add the dependency to the workspace root rather than the workspace itself, which might not be what you want - if you really meant it, make it explicit by running this command again with the -W flag (or --ignore-workspace-root-check).
  • b

    Barnaby

    01/26/2022, 5:53 PM
    solution was to use
    prisma migrate reset --force
    in our CI builds (it was for integration tests)
  • b

    Barnaby

    01/26/2022, 5:56 PM
    ok never mind it's still happening, why on earth would a DB reset command try to yarn install a package?
  • b

    Barnaby

    01/26/2022, 5:56 PM
    ah,
    --skip-generate
  • n

    Nothing.

    01/28/2022, 10:02 AM
    Hello there. Will prisma add support for Deno anytime soon?
    t
    • 2
    • 1
  • n

    Necmettin Begiter

    01/28/2022, 10:21 AM
    Is this the right place to ask for support? prisma client logs "error - TypeError: Do not know how to serialize a BigInt". I did not want to ask on GitHub (there were one-week old untouched issued, and github is not really for support, right?)
  • m

    Manthan Mallikarjun

    01/30/2022, 5:37 AM
    Is there any way to type a JSON field? Either at the prisma/postgres level or some sort of middleware where I can just assign it a typescript type and take care of ensuring the typesafety myself?
  • f

    Fred The Doggy

    01/31/2022, 2:34 AM
    I'm using prisma cloud's data proxy, and I can't figure out how to migrate. anyone have experience with this?
  • f

    Fred The Doggy

    01/31/2022, 2:34 AM
    I have the env variable set
  • f

    Fred The Doggy

    01/31/2022, 2:34 AM
    in my .env
1...151617...23Latest