https://www.prisma.io/ logo
Join Slack
Powered by
# prisma-client
  • p

    Pascal Sthamer

    08/19/2022, 3:49 PM
    After upgrading mysql to 8.0.30, prisma is no longer able to connect:
    Error querying the database: Server error: `ERROR 08S01 (1043): Bad handshake'
    I am unable to write a bug report right now, so just dropping a quick warning here, before you upgrade your mysql server.
    ✅ 1
    n
    • 2
    • 2
  • j

    Jacob Coker-Dukowitz

    08/19/2022, 11:14 PM
    TL;DR: If all calls to the prisma client are synchronous, are queries sent to a single instance of the Prisma client guaranteed to be in the same connection/session when using postgres? Background: I’d like to set a transactional advisory lock where i need some processing between queries. • I can’t use the Sequential Operations feature because i need processing between queries. • I can’t use the Interactive transactions feature because this is for production. • I’d prefer to use a transactional and not a general advisory lock on the db, because then we need to worry about cleaning up orphaned advisory locks in the unlikely but real scenario of a node dying without ‘unlocking’. Why can’t I just use this? Are queries sent to a single instance of the Prisma client not guaranteed to be in the same connection? Running in my repl, it appears to be the same connection.
    Copy code
    prisma.$queryRaw`BEGIN`
    prisma.$queryRaw`pg_advisory_xact_lock(5)`
    // code, processing
    prisma.$queryRaw`pg_advisory_xact_unlock(5)`
    prisma.$queryRaw`COMMIT`
    ✅ 1
    n
    • 2
    • 4
  • y

    Yann Buydens

    08/23/2022, 6:44 AM
    Hi everyone. I’m stuck with a slow query I’d like to speed up. TLDR; this query is super slow. What should I do to speed this query up? Can I do it by adding an index?
    Copy code
    prisma.concept.findMany({
        where: {
          dictionaryId: Number(dictId),
          name: {contains: foo}
        },
        include: {
          _count: {
            select: {
              declarations: true, // including this in the query makes it super slow
            },
          },
        }
      })
    I have a concept table and a declaration table. Concept and declaration have a many to many relationship. The declaration table has more than 500k rows, same goes for concept table. longer explanation: https://www.loom.com/share/ff8d3034898e4ad08b8d19f044d500fe
    j
    • 2
    • 9
  • f

    Florian Thelliez

    08/24/2022, 11:36 AM
    Hi I’m currently trying to upgrade to Prisma 4 and I’m having a little casting issues in some
    $queryRaw()
    Example query:
    Copy code
    const rows = await this.prismaClient.$queryRaw<
      { id: string; location: string }[]
    >(Prisma.sql`
      SELECT id, ST_AsGeoJSON(location) as location,
      FROM something
      WHERE id IN (${Prisma.join(ids)})
    `);
    I get some type errors I didn’t have in previous versions:
    Copy code
    ERROR: operator does not exist: uuid = text
    I’ve tried various way to cast my list of
    ids
    to uuids, but to no avail so far.
    Copy code
    IN (${Prisma.join(ids)}::uuid[]) IN (${Prisma.join(ids)})::uuid[]
    I wouldn’t mind some help there since I might be missing something simple 😅
    👀 1
    n
    • 2
    • 8
  • t

    Trey Holterman

    08/26/2022, 2:54 PM
    Hey! I’m struggling with a strange error creating a new item in a collection that I can’t seem to find anything on. Best explained with my schema files, the failing create call, and the errors that ensue. Here’s my schema for the idea of a ‘report’, which has to belong to a ‘team’.
    Copy code
    model Report {
      id            String        @id @default(auto()) @map("_id") @db.ObjectId
      ...
      team          Team          @relation(fields: [teamId], references: [id])
      teamId        String 
      ...
    }
    Here’s the Team:
    Copy code
    model Team {
      id                   String             @id @map("_id")
      ...
      reports              Report[]
      ...
    }
    I’ve tried creating a number of different ways. I thought the right way was as such:
    Copy code
    const report = await prisma.report.create({
            data: {
                id : newId.toString(),
                teamId:        teamId,
                ...
            },
        });
    Which gives error:
    Copy code
    "Parse errors: [Query parsing/validation error at Mutation.createOneReport.data.ReportCreateInput.team: A value is required but not set"
    Which I interpret to mean it’s missing the ‘team’ object. So I tried:
    Copy code
    const report = await prisma.report.create({
            data: {
                id : newId.toString(),
                ...
                teamId:        teamId,
                team: {
                    connect: {
                        id: teamId,
                    },
                },
                ...
            },
        });
    Which errors out telling me I shouldn’t be including team Id. (will include error in thread). But if I don’t invlude teamId it errors out telling me I should be using teamId. Very confusing since I used to be able to just add teamId in these types of situations
    ✅ 1
    • 1
    • 3
  • m

    Martin Janeček

    08/29/2022, 3:52 PM
    Hello 👋 Has anyone managed to build some kind of query builder or query composer? I've found this discussion in Prisma's repo, but it doesn't really have any answer: https://github.com/prisma/prisma/discussions/12047#discussioncomment-3501408 I've tried to describe my use-case in the comment there. Basically I'd like several small repository/service methods that take care of a single responsibility, and can be combined together into a single strongly-typed query/result. I'd be grateful for really any resource on how to design a DRY, reusable repositories/services with Prisma. Thanks!
    ✅ 1
    a
    • 2
    • 2
  • a

    Austin

    08/29/2022, 6:09 PM
    Hey Gautam! What versions of Prisma and TypeScript are you using?
    g
    • 2
    • 2
  • r

    Rich Starkie

    08/30/2022, 2:08 PM
    hey folks, I'm trying something new ... MongoDB i've managed to convert my schema into a mongo "happy" format, but when I try to write data, I'm getting some errors when I'm linking to documents in other collections
    Copy code
    //schema
    
    model activityLog {
      activityLogId      String                @id @map("_id") @default(uuid())
      activityLogType    activityLogType       @relation(fields: [activityLogTypeId], references: [activityLogType])
      activityLogTypeId  String                @db.ObjectId()
      activityLogMessage String                @db.String
      activityCompleted  Boolean               @default(false)
      createdAt          DateTime              @default(now()) @db.Timestamp
      updatedAt          DateTime              @default(now()) @db.Timestamp
    }
    
    model activityLogType {
      activityLogType     String                @id @map("_id")  @db.String
      createdAt           DateTime              @default(now()) @db.Timestamp
      updatedAt           DateTime              @default(now()) @db.Timestamp
      activityLog         activityLog[]
    }
    when I try to do
    Copy code
    await prisma.activityLog.create({
        data: {
          activityLogType: {
            activityLogType: "Start"
          },
          activityLogMessage: "Start Seeding",
          activityCompleted: true
        }
      })
    The
    Start
    document already exists in the
    activityLogTypes
    collection it complains that the
    activityLogType
    does not exist schema I'm probably doing something wrong, and its likely a n00b error for Mongo, but any help would be suggested.
    👀 1
    a
    • 2
    • 2
  • j

    James Fox

    08/30/2022, 5:31 PM
    Hi there - I noticed the release today with preview support for field reference support on query filters. Curious if this is a precursor or helps in any way to address this issue (sorting by foreign key fields): https://github.com/prisma/prisma/issues/5837
    ✅ 1
    n
    • 2
    • 1
  • c

    Casey Chow

    09/01/2022, 7:11 PM
    Looks like it’s working as intended. The only way to make this work is to select the value on both, otherwise there’s only one case where birthdate is a value so Typescript can’t safely let you use the property.
  • k

    Kay Khan

    09/05/2022, 2:10 PM
    Hi friends, i wanted to ask about naming convention of models and how it relates to reusing code and pulling/introspection. Let me explain the scenario. Folder structure
    Copy code
    /core/prisma/schema.prisma
    /lambda/prisma/schema.prisma
    Core - This folder contains some core logic and is often "shared" code used by folder
    lambda
    . Lambda folder is a serverless function more on that later.
    core/prisma/schema.prisma
    Copy code
    model Collection {
        id                String    @id @default(auto()) @map("_id") @db.ObjectId
        network           String
        contract_address  String    @unique
        @@map("collections")
    }
    The convention for declaring a model here is familiar to the docs. https://www.prisma.io/docs/concepts/components/prisma-schema - Singular with a capital first letter.
    core/models/collections.ts
    Inside of this file im doing some common functionality like finding, inserting etc. Note: the model name that is being used "collection". Generated by the prisma library based on schema.prisma.
    Copy code
    export const FindCollections = async () => {
        try {
            const contracts = await PrismaService.collection.findMany();
    
            return [contracts, null] as const;
        } catch (err) {
            Logger.error({ kind: "FindCollections", error: err.name, stack_trace: err.stack });
            return [null, err] as const;
        }
    };
    Up until now, there are no problems. Now lets introduce my lambda. I have this lambda folder which has my serverless function im going to deploy and i want to use "FindCollections" function within the core folder which has already been created. However in my lambda folder, i need to introspect the database and package the engine. but when i introspect the database the model name becomes a problem.
    lambda/prisma/prisma.schema
    Copy code
    model collections {
      id                String   @id @default(auto()) @map("_id") @db.ObjectId
      contract_address  String
      ...
    }
    You can now see its all lowercase with plural. Now with this introspected schema, my existing "FindCollections" function no longer works, because the model name is different.
    InsertCollections","stack_trace":"Error: Could not find mapping for model Collection\n
    What is the suggestion for this usecase? There are 2 solutions i can think of but im wondering what you guys think.
    ✅ 1
    h
    • 2
    • 1
  • n

    Niv Oppenhaim

    09/07/2022, 9:16 AM
    Hi! Is there anyway to use the prisma CLI to check if the remote schema matches the local one?
    h
    • 2
    • 3
  • m

    Mike Willbanks

    09/07/2022, 7:54 PM
    Looks like someone accidentially packaged prisma with the debian libquery_engine in the
    internals
    dist
    folder 😕
    👀 1
    a
    • 2
    • 1
  • h

    Harshit

    09/08/2022, 9:14 AM
    Looks like you are hitting this bug: https://github.com/prisma/prisma/issues/5715 Please add +1 in the issue to get it up the priority list.
    👍 1
  • m

    Mike Willbanks

    09/08/2022, 3:46 PM
    FYI opened a ticket for the accidentially bundled libquery_engine: https://github.com/prisma/prisma/issues/15244
    👍 1
  • k

    Kay Khan

    09/09/2022, 8:03 AM
    Hi friends, i am getting the following error when trying to insert into mongodb: unfortunately prisma does not indicate the name of field that is the problem in this error message.
    Copy code
    16 try {
      17     const response = await PrismaService.$transaction(
      18         payload.map((p) =>
    → 19             PrismaService.salesByContractAddress.upsert(
    Error parsing GraphQL query: query parse error: Parse error at 23:14
    number too large to fit in target type
    is there some way i can determine which field in the schema is the problem?
    ✅ 1
    h
    • 2
    • 1
  • k

    Kay Khan

    09/09/2022, 9:28 AM
    Does prisma support mongodb's
    Decimal128
    ?
    ✅ 1
    r
    • 2
    • 2
  • b

    bitsofinfo

    09/09/2022, 4:59 PM
    Hi! new to prisma and trying to understand some basics, trying to do something simple (or seems should be simple) but running into some typing crazyness.
    Copy code
    async update(updatedBy:Principal, data: Prisma.BlogUpdateInput): Promise<BlogEntry> {
            data.updatedBy = updateBy.principalId;
            return await this.prisma.blogEntry.update({
                                    where: {
                                        id: data.id
                                    },
                                    data: data
                                });
        }
    but this yields me an syntax error stating:
    Copy code
    Type 'string | StringFieldUpdateOperationsInput' is not assignable to type 'string'.
      Type 'StringFieldUpdateOperationsInput' is not assignable to type 'string'.ts(2322)
    index.d.ts(4311, 5): The expected type comes from property 'id' which is declared here on type 'BlogEntryWhereUniqueInput'
    BlogUpdateInput.id is just a string... what "generated" type should I be using to on my
    update()
    method that wraps the call to prisma? This is a bit confusing
    👀 1
    h
    v
    • 3
    • 2
  • o

    Ofir Cohen

    09/09/2022, 8:55 PM
    Hi, is it good practice to check-in the auto-generated clients generated by
    npx prisma generate
    to Git, or should I run this command as part of my
    prestart
    step in
    npm
    ? Context: I am deploying my web app in an air-gapped system and the
    npx prisma generate
    tried to fetch some files from an online URL and failed miserably. Now I’m debating between: 1. Runing
    npx prisma generate
    as part of the Docker build - to online fetch the auto-generated files 2. Checking-in the prisma client to Git
    ✅ 1
    h
    • 2
    • 1
  • o

    Ofir Cohen

    09/09/2022, 11:30 PM
    In simpler words, should Prisma client be version controlled (Git) or auto-generated through
    npx prisma generate
    on
    npm run dev
    ?
  • o

    Ofir Cohen

    09/10/2022, 12:35 AM
    I now realize that what failed is the query engine download, I could cache it locally or simply run
    npx prisma generate
    as part of the Docker build step and have it cached as a side effect.
    ✅ 1
  • m

    Mattèo Gauthier

    09/13/2022, 10:40 AM
    Hey 🙌 Does someone know how to check connection status with prisma client (like an healthcheck) ?
    ✅ 1
    r
    • 2
    • 1
  • a

    Ashe Magalhaes

    09/14/2022, 11:30 PM
    Hi there! New to this channel so please redirect me if this should go elsewhere. I'm using prisma with a mysql planetscale backend. I'm getting an error about ROW_NUMBER() in a
    prisma.$queryRaw
    Something like this, which works fine on my planetscale console:
    Copy code
    const query = `select ROW_NUMBER() over() FROM contacts`;
    Results in the error:
    Copy code
    Code: `1105`. Message: `unknown error: syntax error at position 26`
    Anyone know why prisma can't seem to handle
    ROW_NUMBER()
    function?
    👀 1
    ✅ 1
    r
    n
    • 3
    • 10
  • c

    Centux

    09/18/2022, 8:13 PM
    Hi! Can I perform a full text search with cockroach db?
    ✅ 1
    r
    • 2
    • 1
  • r

    Robert Grimes

    09/19/2022, 4:27 AM
    If I upgrade from prisma 3.x to 4.x will it stop performing wasted queries to get the results of inserts?
    👀 1
    ✅ 1
    j
    r
    • 3
    • 6
  • r

    Rox

    09/20/2022, 3:20 AM
    HI there! Currently debugging some crazy stuff with generating a prisma client with a custom output path into a monorepo man that's a lot of buzzwords I have found several open issues (and some old closed ones) with people who seem to have the same problem, wondering if this bug isn't a priority and I should just switch everything off of prisma? Issues are here: Technically Closed: https://github.com/prisma/prisma/issues/10512, Open: https://github.com/prisma/prisma/issues/13233, https://github.com/prisma/prisma/issues/12588, https://github.com/prisma/prisma/issues/10433 (my exact issue) I have figured out how to fix this sort of! I just had to manually edit the generated index.js file 😂 Details in the thread Hoping to get a real fix for this ❤️
    ✅ 1
    n
    • 2
    • 4
  • r

    Robert Grimes

    09/20/2022, 3:46 AM
    How do I explicitly get a new connection from a prisma object?
    ✅ 1
    n
    • 2
    • 3
  • m

    Mike Willbanks

    09/20/2022, 8:14 PM
    is there a way to dynamically create or notify the prisma client to new tables without having to rebuild the entire client? the example specifically that comes into play is if i am creating more or less a CMS that allows the individual to create a data model (think more amongst the lines of strapi / contentful), i would like to generate out a table structure for that and then allow prisma to understand it without having to update the schema file and then run migrations and generate the client once again, i am sure some form of generation needs to happen but to be able to dynamically add in additional tables without the full generator process running again to create the underlying client would be nice.
    👀 1
    ✅ 1
    n
    • 2
    • 2
  • r

    Ryan Roline

    09/21/2022, 10:18 PM
    Hello - can someone please take a look this thread? I believe i may have posted it in the wrong place https://prisma.slack.com/archives/CA491RJH0/p1663781800291489
    ✅ 1
  • v

    Vladi Stevanovic

    09/23/2022, 10:44 AM
    👋 Hello everyone! To streamline support for our Community, all questions about the Prisma ORM (Client, Studio, Migrate) will now be answered in #orm-help channel, and this channel will be archived next week is now archived. We hope that this will allow us to help you more quickly and share the knowledge among all our community members. 😊 If you have any pending questions / issues, feel free to resolve them in the current threads or move the conversation into #orm-help! 🧑‍💻 Happy coding!