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

    Ross Cooperman

    07/08/2022, 8:23 PM
    👋 i'm trying to find a solution to a problem that i can't possibly be the first person to tackle but i can't really find any working examples of solutions and nothing great is coming to mind
  • r

    Ross Cooperman

    07/08/2022, 8:24 PM
    we use prisma + apollo server and i'm trying to implement https://relay.dev/graphql/objectidentification.htm on a relatively mature schema
  • r

    Ross Cooperman

    07/08/2022, 8:25 PM
    we don't really wrap any prisma objects in our own models and it's hard to see how i can possibly implement
    __resolveType()
    on a Prisma object
  • r

    Ross Cooperman

    07/08/2022, 8:26 PM
    possible solutions i've thought about are wrapping prisma objects in something introspectable or changing our database IDs to contain the type so we can infer the type from id
  • r

    Ross Cooperman

    07/08/2022, 8:26 PM
    neither really feels great tbh though
  • r

    Ross Cooperman

    07/08/2022, 8:27 PM
    what i really want is just some properly on the objects prisma returns that can tell me what type of object it is (since reflection in typescript is so bad)
  • r

    Ross Cooperman

    07/08/2022, 8:27 PM
    i'd also accept some built in support for annotating the types prisma generates using gross typescript reflection support but that doesn't seem to really be possible
    👀 2
    n
    • 2
    • 7
  • r

    Rogerio Orioli

    07/10/2022, 11:48 AM
    Hello people
  • r

    Rogerio Orioli

    07/10/2022, 11:50 AM
    i have a question ! how i can hide password when i do this query ? please.
    Copy code
    const prisma = new PrismaClient()
      const posts  = await prisma.post.findMany({
        include : {
          user : true
        },
        orderBy: {
          created_at: 'desc',
        },
        
    
      })
    ✅ 1
    m
    m
    • 3
    • 33
  • k

    Kay Khan

    07/11/2022, 10:01 AM
    Hi friends is an upsertMany possible? right now i can onlything i would have to do multiple upserts using transaction?
    ✅ 1
    n
    • 2
    • 4
  • m

    Mischa

    07/12/2022, 5:16 AM
    is there any way to tell prisma where the schema.prisma file is? trying to do more deterministic bundling for lambda functions and it's not easy to put it in the same dir as the script (related: it would be really cool if prisma didn't use
    __dirname
    to find it because it doesn't exist in ESM)
    🙌 1
    m
    n
    • 3
    • 6
  • k

    Kay Khan

    07/12/2022, 10:10 AM
    I am building a serverless function using the serverless framework. However im having an issue with running it locally prisma/schema.prisma
    Copy code
    generator client {
        provider      = "prisma-client-js"
        binaryTargets = ["native", "rhel-openssl-1.0.x"]
    }
    serverless.ts
    Copy code
    package: {
            individually: true,
            patterns: [
                "!node_modules/.prisma/client/libquery_engine-*",
                "node_modules/.prisma/client/libquery_engine-rhel-*",
                "!node_modules/prisma/libquery_engine-*",
                "!node_modules/@prisma/engines/**",
            ],
        },
    Copy code
    npx prisma generate && npm install
    Copy code
    sls invoke local -f main
    ✖️ Error: ENOENT: no such file or directory, open ''/.esbuild/.build/node_modules/.prisma/client/schema.prisma'
    What am i doing wrong here? attempting to follow this example: https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/aws-lambda • note: i am using the serverless
    aws-nodejs-typescirpt
    template which uses serverless-esbuild and not serverless-webpack
    m
    • 2
    • 88
  • s

    Salvador Lopez Mendoza

    07/13/2022, 10:04 PM
    Question about middleware, I want to write another `Event`record into the db after a create query has succeeded, is the right place for this logic 🤔
    ✅ 1
    n
    • 2
    • 2
  • v

    Viktor Demčák

    07/14/2022, 9:51 AM
    Hello, should I have one export of PrismaClient() from index.ts or create a new one in each file where I want to use prisma?
    ✅ 1
    a
    • 2
    • 2
  • y

    Yaakov

    07/14/2022, 9:08 PM
    I'm unable to nullify a many-to-one and update a one-to-one at the same time. Can someone please help? `Error: Unknown arg
    team_id
    in data.team_id for type PersonUpdateInput. Did you mean
    team
    ?`
    Copy code
    model Person {
      id         Int    @id
      first_name String
      last_name  String
      team_id    Int?
    
      personData PersonData?
      team       Team?       @relation(fields: [team_id], references: [id])
    }
    
    model PersonData {
      person_id      Int    @id
      favorite_color String
    
      person Person @relation(fields: [person_id], references: [id])
    }
    
    model Team {
      id   Int    @id
      name String
    
      people Person[]
    }
    Copy code
    await prisma.person.update({
      where: {
        id: 1,
      },
      data: {
        team_id: null,
        personData: {
          update: {
            favorite_color: 'Purple',
          },
        },
      },
    });
    👀 1
    n
    • 2
    • 6
  • r

    Ridhwaan Shakeel

    07/16/2022, 5:52 PM
    hello, I upgraded prisma client from version 3.14 to version 4.0.0 (latest)
    Copy code
    PrismaClientKnownRequestError:
    [0] Invalid `prisma.product.findMany()` invocation in
    [0] /app/server/data/index.js:148:37
    [0]
    [0]   145 }
    [0]   146
    [0]   147 const getTopProducts = async () => {
    [0] → 148   const result = await prisma.product.findMany(
    [0]   Inconsistent column data: Conversion failed: Value 2847246203 does not fit in an INT column, try migrating the 'revenue' column type to BIGINT
    [0]     at RequestHandler.handleRequestError (/server/node_modules/@prisma/client/runtime/index.js:49670:13)
    [0]     at RequestHandler.request (/server/node_modules/@prisma/client/runtime/index.js:49652:12)
    [0]     at async PrismaClient._request (/server/node_modules/@prisma/client/runtime/index.js:50572:18)
    [0]     at async getTopProducts (/server/data/index.js:148:18)
    [0]     at async /server/routes/index.js:142:12 {
    [0]   code: 'P2023',
    [0]   clientVersion: '4.0.0',
    [0]   meta: {
    [0]     message: "Conversion failed: Value 2847246203 does not fit in an INT column, try migrating the 'revenue' column type to BIGINT"
    [0]   }
    [0] }
    always used the Prisma SQLite connector, didn't have this problem before upgrading to version 4.0.0 here is the model
    Copy code
    datasource db {
      provider = "sqlite"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider = "prisma-client-js"
      previewFeatures = []
    }
    
    model Product {
    ...
    revenue				Int
    ...
    }
    ✅ 1
    n
    • 2
    • 1
  • d

    Dhaval Vira

    07/17/2022, 2:34 AM
    Hello, I am new to Prisma, and I have a Postgres RAW query which is nested Inner Queries, I wanted to know that how I can write that using Prisma? below is my RAW Query..
    Copy code
    SELECT * FROM tableName WHERE id NOT IN (SELECT columnName FROM tableName WHERE (startDateInputFromUser between startDate and endDate) or (endDateInputFromUser between startDate and endDate))
    here in WHERE clauses the
    startDateInputFromUser
    &
    endDateInputFromUser
    it's from the User Input & other
    startDate
    &
    endDate
    is the Table Column Name... can anyone help me how I can write this query in the Prisma ORM?
    ✅ 1
    n
    • 2
    • 1
  • r

    Roland Sankara

    07/19/2022, 5:45 PM
    Hi everyone. I recently created a simple REST API (using Express, Prisma and PostgreSQL) which works fine. Am now currently trying to write some unit tests but am wondering how I can create a test environment with it's own test database. Is it possible to programmatically change the DATABASE_URL in the
    schema.prisma
    file? For example: Given DEVELOPMENT, TEST, PRODUCTION environments, I would maybe create this kind of logic;
    Copy code
    const { DEVELOPMENT, PRODUCTION, LOCAL } = require("./envTypes");
    let DB_URL;
    switch (process.env.NODE_ENV) 
    {  case DEVELOPMENT:    
         DB_URL = process.env.DB_URL_DEV;    
          break;  
       case PRODUCTION:    
         DB_URL = process.env.DB_URL_PROD;    
         break;   
       case LOCAL:    
         DB_URL = process.env.DB_URL_LOC;    
         break;  
       default:    
          DB_URL = process.env.DB_URL;
    }
    ✅ 1
    a
    • 2
    • 2
  • r

    Renaud Chaput

    07/20/2022, 8:38 AM
    Are there any docs on how to properly setup OpenTelemetry instrumentation in
    @prisma/client
    ? I enabled the
    previewFeatures
    flag and see
    request
    spans, but they dont include any attributes
    ✅ 1
    n
    • 2
    • 2
  • k

    Kay Khan

    07/20/2022, 3:24 PM
    I have a mock created like the following:
    Copy code
    import { PrismaClient } from "@prisma/client";
    import { mockDeep, mockReset, DeepMockProxy } from "jest-mock-extended";
    import { PrismaService } from "@services/prisma.service";
    
    jest.mock("@services/prisma.service", () => ({
        __esModule: true,
        PrismaService: mockDeep<PrismaClient>(),
    }));
    
    beforeEach(() => {
        mockReset(PrismaMock);
    });
    
    export const PrismaMock = PrismaService as unknown as DeepMockProxy<PrismaClient>;
    and then in my test i am using it... However its still connecting to the live (local) db.
    Copy code
    PrismaMock.nft_collection.create.mockResolvedValueOnce({});
    
    const [response, error] = await CreateCollection(payload);
    Not sure whats going on, why Prisma is not being mocked?
    ✅ 1
    • 1
    • 1
  • m

    Matt Mueller (Prisma Client PM)

    07/25/2022, 8:59 PM
    Has anyone had a chance to try the new Prisma Metrics API in 3.15.0 yet? • You can watch a demo video here:

    https://www.youtube.com/watch?v=B3Mh3yGRZ5U&amp;t=580s▾

    • Metrics documentation is here: https://www.prisma.io/docs/concepts/components/prisma-client/metrics Please let me know if you give it a go and what you think of it!
    👀 1
  • e

    Eric Tsang

    07/30/2022, 7:39 AM
    Hello, I’m having trouble modeling a pair in my schema. e.g. I’m trying to model
    Pair
    being a unique pair of
    Tokens
    — so far my schema is:
    Copy code
    model Token {
      id      Int    @id @default(autoincrement())
      chainId Int
      address String
      name    String
    
      @@unique([chainId, name])
    }
    
    model Pair {
      id                  Int                   @id @default(autoincrement())
      chainId             Int
      name                String
      token0Id            Int
      token1Id            Int
    
      @@unique([chainId, name])
    }
    Any hints on how to do this?
    ✅ 1
    r
    • 2
    • 4
  • e

    Eric Tsang

    07/30/2022, 7:40 AM
    It feels like it should be 1:many? Or is it many:many?
  • l

    Larry Mickie

    07/30/2022, 5:21 PM
    What is the best way to handle nested one to many self relations? I tried:
    Copy code
    model Item {
      id             String   @id @default(uuid())
      relatedItemsId String[]
      relatedItems   Item[]   @relation("RelatedItems", fields: [relatedItemsId], references: [id])
    }
    But it throwing and error in my schema file.
    ✅ 1
    r
    • 2
    • 3
  • l

    Leo

    07/30/2022, 8:49 PM
    So, I'm having issues with Cloudflare Pages: [pages:err] ReferenceError: DATABASE_URL is not defined. Attempted to access binding using global in modules. I read a bit about 4.2.0 making it possible to override the db url through the PrismaClient constructor (see https://github.com/prisma/prisma/issues/13771). Is this possible yet?
    ✅ 1
    a
    • 2
    • 1
  • m

    Mischa

    08/01/2022, 6:22 PM
    am i doing something wrong here? i randomly get this error in my tests
    Copy code
    [test:*backend] Invalid `prisma.$queryRaw()` invocation:
    [test:*backend] 
    [test:*backend] 
    [test:*backend]   Raw query failed. Code: `22P03`. Message: `db error: ERROR: incorrect binary data format in bind parameter 1`
    [test:*backend]  ❯ RequestHandler.handleRequestError node_modules/@prisma/client/runtime/index.js:49670:13
    [test:*backend]  ❯ RequestHandler.request node_modules/@prisma/client/runtime/index.js:49652:12
    [test:*backend]  ❯ Proxy._request node_modules/@prisma/client/runtime/index.js:50572:18
    [test:*backend]  ❯ EmailCandidateSentRepository.getUnsentEmails packages/service/src/repo/repository/emailCandidateSent.ts:89:17
    [test:*backend]      87|       ${userId ? sql` AND "userId"=${userId}::uuid` : Prisma.empty}
    [test:*backend]      88|     `
    [test:*backend]      89|     const rows = await prisma.c.$queryRaw<{ id: string }[]>`
    [test:*backend]        |                 ^
    [test:*backend]      90|       SELECT id FROM "EmailCandidateSent"
    [test:*backend]      91|         WHERE ${whereFilters}
    Untitled.ts
  • c

    Casey Chow

    07/30/2022, 6:29 PM
    Is there a way to change the connection URL between connections? I’m trying to set up database test isolation.
    👀 1
    n
    v
    • 3
    • 5
  • j

    Jeremy Hinegardner

    08/04/2022, 4:09 PM
    Hi all, A recent change to heroku postgresql (https://devcenter.heroku.com/changelog-items/2446) is causing us some problems because extensions are now by default install in the
    heroku_ext
    namespace, and can only be installed in the
    heroku_ext
    namespace. Our application uses a custom schema
    mobile
    in our datasource definition
    schema=mobile
    in data source url as per Postgresql connection documentation in prisma. The problem is that because we are using a custom schema, it looks like the Quaint db driver fully clobbers the
    search_path
    to just
    set search_path = mobile
    which makes our migrations fail when looking for installed extensions. A short form of the fully failing migration is: And then this is our output:
    Copy code
    Prisma schema loaded from db/schema.prisma
    Datasource "db": PostgreSQL database "d3o13esjuu8i9a", schema "mobile" at "<http://ec2-3-222-74-92.compute-1.amazonaws.com:5432|ec2-3-222-74-92.compute-1.amazonaws.com:5432>"
    18 migrations found in prisma/migrations
    Applying migration `20220323211357_create_mobile_schema` // this is CREATE SCHEMA IF NOT EXISTS mobile;
    Applying migration `20220323223149_enable_extensions`   // this contains CREATE EXTENSION IF NOT EXISTS "citext" - and succeeds
    Applying migration `20220324172504_create_users`
    Error: P3018
    A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
    Migration name: 20220324172504_create_users
    Database error code: 42704
    Database error:
    ERROR: type "citext" does not exist // I'm guess this is because the citext extension is now in the `heroku_ext` namespace which is not in the search_path
    Position:
      0
      1 -- CreateTable
      2 CREATE TABLE "users" (
      3     "id" UUID NOT NULL DEFAULT gen_random_uuid(),
      4     "email" CITEXT NOT NULL,
    
    DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42704), message: "type \"citext\" does not exist", detail: None, hint: None, position: Some(Original(101)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") }
    I'm pretty sure that is because at the time that the create table is happening, the search path is only
    mobile
    and not
    mobile, heroku_ext
    Is this the right forum to post this or should I be posting this to the GitHub Issues for prisma, or to the prisma-engines repos?
    • 1
    • 1
  • k

    Kay Khan

    08/05/2022, 2:03 PM
    I have a repo that is dedicated for my database and making migration schema changes. So far in a separate microservice i have an api that simply introspects the database to get the latest table schemas and works with the orm. Rather than introspecting the database, does it make sense to publish the generated prisma client to a private npm package? so instead my api microservice, rather than introspecting the database to look for latest changes, it could just update to the latest npm version of the package? wondering if anyone else has gone down a similar usecase or rather than republishing the entire PrismaClient, is it better to publish just the schema.prisma and hae the other microservice run prisma generate?
    ✅ 1
    n
    • 2
    • 9
  • j

    James A

    08/08/2022, 1:40 PM
    Hi all 👋, I am trying to deploy my service to heroku but i keep getting the error:
    Error: Not Found <https://binaries.prisma.sh/all_commits/369b3694b7edb869fad14827a33ad3f3f49bbc20/debian-openssl-3.0.x/query-engine.gz>
    Whenever it tries to run
    npx prisma generate
    as part of my build script. I have tried installing the cli globally on heroku still i get same error. Anyone encountered this before? please how do i resolve it? Thanks
    ✅ 1
    👀 1
    r
    • 2
    • 2
1...1920212223Latest