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

    rcastell

    09/21/2021, 9:29 PM
    Hey! Have a question, how should I create the query to replace "exists" in prisma. I haven't found anything related to this topic in the documentation. Example: SELECT * FROM
    table1
    WHERE
    id
    =
    1
    AND EXISTS (SELECT * FROM
    table2
    WHERE
    contacts
    .
    id
    = 3)
    r
    • 2
    • 23
  • r

    rcastell

    09/21/2021, 9:31 PM
    Or where i could find information about it?
  • c

    Chris Tsongas

    09/21/2021, 11:23 PM
    When doing
    @default(autoincrement())
    is there a way to set the autoincrement start value?
    r
    • 2
    • 1
  • c

    Casey Chow

    09/22/2021, 12:50 AM
    Has anyone been able to integrate Prisma with something like IntegreSQL? The only thing I can find to that extent is this old blog post: https://stories.abletech.nz/what-does-it-mean-to-go-serverless-183582231cdd I’ve been working through this approach but it doesn’t seem like Prisma likes the approach of disconnecting then reconnecting to different URLs.
    r
    • 2
    • 3
  • s

    SKhan

    09/22/2021, 4:02 AM
    Hi Guys, the following query returns entries from the table 'changeLog' for teamId (specified) and conditional where property 'teamMessageId' & 'commentId' is not null. However, it actually ignores the specified teamId and returns for all teamIds. What am I doing wrong?
    Copy code
    const teamMsgs = await db.changeLog.findMany({
        where: {
          AND: [
            {
              teamId: teamData?.teamId,
            },
            {
              OR: [
                {
                  NOT: {
                    teamMessageId: null,
                  },
                },
                {
                  NOT: {
                    commentId: null,
                  },
                },
              ],
            },
          ],
        },
        select: {
        ...
    r
    • 2
    • 8
  • s

    See Jee

    09/22/2021, 5:35 AM
    Copy code
    await this.prismaService.post.findFirst({
      where: {
        postUid,
      }
    });
    I want to duplicate na data result, is there a function out there I can use?
    r
    • 2
    • 4
  • o

    Octal pixel

    09/22/2021, 7:40 AM
    Hey guys! Is there a way to add where close when doing a _count in findMany
    Copy code
    await prisma.posts.findMany({
        where: {
          company_id: companyId,
        },
        select: {
          _count: {
            select: {
              post: true,
            },
          },
          post: {
            where: {
              status: "published",
            },
          },
        },
      });
    r
    • 2
    • 4
  • o

    Octal pixel

    09/22/2021, 7:41 AM
    I want to get the count of the total posts and the posts that are published
  • d

    Dmitri Pisarev

    09/22/2021, 11:19 AM
    Hi! Is it possible to add some kind of custom attribute to Prisma schema fields. I want to build a declarative security layer and define which permissions are required to read/write a certain field. Kinda like:
    Copy code
    email      String?     @privilege("owner")
    Or do I have to use comments for that?
    r
    • 2
    • 6
  • s

    Slackbot

    09/22/2021, 12:11 PM
    This message was deleted.
    s
    p
    • 3
    • 2
  • t

    thdxr

    09/22/2021, 1:05 PM
    Where can I read more about the Prisma data proxy? Is it basically a hosted version of the query engine so that in serverless environments each function isn't spawning it?
    a
    • 2
    • 3
  • v

    Vladi Stevanovic

    09/22/2021, 1:45 PM
    👋 If you're brand new to Prisma or looking for a refresher, we've put together a top 5 Prisma courses list here 👉 I recommend checking out "End to End React with Prisma" - an Udemy course by our Prisma Ambassador Stephen Jensen, which you can take for ✨ FREE ✨ using this code: ENDTOENDSEP22* *Valid until this Sat, Sept 25th.
    💯 1
    🙌 1
  • m

    Mattias Rådemar

    09/22/2021, 2:08 PM
    Hello! I'm trying to work with webpack and prisma. Need to bundle our Node Typescript code in to Javascript. After running webpack I'm getting the error
    Error: PrismaClient is unable to be run in the browser.
    . I was reading about that I might need to copy over some binaries using
    copy-webpack-plugin
    but I'm not really sure on exactly what needs to be copied. Any pointers?
    • 1
    • 2
  • f

    Fran Dios

    09/22/2021, 6:18 PM
    Hi! I’ve upgraded from P1 to 3.0.2 and I’m having problems with n-m relations. I had a few
    @relationTable
    in P1 and I have renamed all of them in DB (PG9) to follow P2 conventions for implicit n-m relations. However, it now throws with these tables something like
    The column _AddressBook.B does not exist in the current database.
    at run time. And same happens when trying
    db push
    command:
    Added the required column B to the _AddressBook table without a default value
    . Any ideas? The table looks like this:
    r
    • 2
    • 7
  • c

    Christian Goebel

    09/22/2021, 6:39 PM
    I'm currently struggeling with creating a new entry that is supposed to include a many to many relation. I can see that for input one of the following types is allowed: UserCreateInput or UserUncheckedCreateInput. However, if I run my query, it says "Unknown arg
    groups
    in create.groups for type UserUncheckedCreateInput." which is right, "groups" is not part of "UserUncheckedCreateInput" type, but it is of "UserCreateInput" type. I searched around on when prisma expects "Unchecked" Input type and when not, but couldn't find any. Who knows?
    r
    • 2
    • 8
  • k

    kfredericks

    09/22/2021, 9:29 PM
    Hi! Has there been any progress on allowing bridged queries for explicit m:n relations?
    r
    • 2
    • 5
  • m

    Michael Aubry

    09/22/2021, 11:11 PM
    Is anyone familiar with this error
    The provided value for the column is too long for the column's type. Column: (not available)
    h
    • 2
    • 1
  • i

    inlightmedia

    09/23/2021, 1:51 AM
    Has anyone run into this error when using prisma1 import: Failure inserting into relationtable _CodeToObj with ids StringIdGCValue(cjtflw2ilq6qp08799l21x89r) and StringIdGCValue(cjtfly6jxroq50879hp2avno8). Cause: duplicate key value violates unique constraint “_CodeToObj_AB_unique”\n Detail: Key (“A”, “B”)=(cjtflw2biq6ni08798alm3tyl, cjtflwoqeqlnj0879ijz8xb29) already exists. https://github.com/prisma/prisma1/issues/4216 Removing the .import seems to be the only working solution but we don’t have a .import folder.
    r
    • 2
    • 1
  • k

    kapil verma

    09/23/2021, 4:57 AM
    hi, so prisma is not compiling for me. this is what the errors look like
  • k

    kapil verma

    09/23/2021, 4:57 AM
    Copy code
    > api@1.0.0 build
    > npm run clean && tsc && npm run prisma generate
    
    
    > api@1.0.0 clean
    > rm -rf dist
    
    node_modules/.prisma/client/index.d.ts(4002,43): error TS2344: Type 'S["include"][P]' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'S["include"]["updates"]' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'S["include"]["updates"]' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
          Type 'S["include"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
            Type 'S["include"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
              Type 'S["include"][P]' is not assignable to type 'DiagramUpdateArgs'.
                Type 'S["include"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
                  Type 'S["include"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4013,43): error TS2344: Type 'S["select"][P]' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'S["select"]["updates"]' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'S["select"]["updates"]' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
          Type 'S["select"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
            Type 'S["select"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
              Type 'S["select"][P]' is not assignable to type 'DiagramUpdateArgs'.
                Type 'S["select"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
                  Type 'S["select"]["updates"]' is not assignable to type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4357,197): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateFindManyArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateFindManyArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Property 'data' is missing in type 'DiagramUpdateFindManyArgs' but required in type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4558,15): error TS2300: Duplicate identifier 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4878,218): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateFindUniqueArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateFindUniqueArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Property 'data' is missing in type 'DiagramUpdateFindUniqueArgs' but required in type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4878,344): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
    node_modules/.prisma/client/index.d.ts(4895,217): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateFindFirstArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateFindFirstArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Property 'data' is missing in type 'DiagramUpdateFindFirstArgs' but required in type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4895,343): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
    node_modules/.prisma/client/index.d.ts(4915,104): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateFindManyArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'T' is not assignable to type 'DiagramUpdateArgs'.
          Type 'DiagramUpdateFindManyArgs' is not assignable to type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4931,119): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateCreateArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateCreateArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Property 'where' is missing in type 'DiagramUpdateCreateArgs' but required in type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4963,119): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateDeleteArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateDeleteArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Property 'data' is missing in type 'DiagramUpdateDeleteArgs' but required in type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(4982,119): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateUpdateArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateUpdateArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Type 'DiagramUpdateUpdateArgs' is not assignable to type 'DiagramUpdateArgs'.
              Types of property 'include' are incompatible.
                Type 'DiagramUpdateInclude | null | undefined' is not assignable to type 'DiagramInclude | null | undefined'.
                  Type 'DiagramUpdateInclude' has no properties in common with type 'DiagramInclude'.
    node_modules/.prisma/client/index.d.ts(5040,119): error TS2344: Type 'T' does not satisfy the constraint 'boolean | DiagramUpdateArgs | null | undefined'.
      Type 'DiagramUpdateUpsertArgs' is not assignable to type 'boolean | DiagramUpdateArgs | null | undefined'.
        Type 'DiagramUpdateUpsertArgs' is not assignable to type 'DiagramUpdateArgs'.
          Type 'T' is not assignable to type 'DiagramUpdateArgs'.
            Property 'data' is missing in type 'DiagramUpdateUpsertArgs' but required in type 'DiagramUpdateArgs'.
    node_modules/.prisma/client/index.d.ts(5491,15): error TS2300: Duplicate identifier 'DiagramUpdateArgs'.
    r
    • 2
    • 3
  • h

    Harsha MV

    09/23/2021, 5:46 AM
    I keep getting this error.
    Copy code
    PrismaClientInitializationError: 
    Invalid `prisma.project.findMany()` invocation:
    
    
      Error querying the database: db error: FATAL: remaining connection slots are reserved for non-replication superuser connections
        at cb (/Users/harshamv/Sites/nftvoltclub/node_modules/@prisma/client/runtime/index.js:36958:17)
        at async handler (webpack-internal:///./pages/api/projects/new.js:19:24)
        at async Object.apiResolver (/Users/harshamv/Sites/nftvoltclub/node_modules/next/dist/server/api-utils.js:101:9)
        at async DevServer.handleApiRequest (/Users/harshamv/Sites/nftvoltclub/node_modules/next/dist/server/next-server.js:760:9)
        at async Object.fn (/Users/harshamv/Sites/nftvoltclub/node_modules/next/dist/server/next-server.js:651:37)
        at async Router.execute (/Users/harshamv/Sites/nftvoltclub/node_modules/next/dist/server/router.js:205:32)
        at async DevServer.run (/Users/harshamv/Sites/nftvoltclub/node_modules/next/dist/server/next-server.js:825:29)
        at async DevServer.handleRequest (/Users/harshamv/Sites/nftvoltclub/node_modules/next/dist/server/next-server.js:292:20) {
      clientVersion: '3.1.1',
      errorCode: undefined
    }
    PrismaClientInitializationError:
  • h

    Harsha MV

    09/23/2021, 5:46 AM
    this is my prisma configuration file:
    Copy code
    import { PrismaClient } from '@prisma/client';
    Copy code
    const prisma = new PrismaClient();
    export default prisma;
  • e

    ezeikel

    09/23/2021, 7:56 AM
    Hey all, using the latest version Prisma on a new side project after not using it for a long time - I had previously used v1. I remember with v1, running
    prisma generate
    and having a file be created with all the possible CRUD operations based on my Models. Then i could just look at that file and find the Prisma created function that I needed and add it to my Query/Mutation. It doesn't seem to work like this in the latest version? How do I know what functions I can call? Or is it just the generic ones listed here - https://www.prisma.io/docs/reference/api-reference/prisma-client-reference
    r
    • 2
    • 1
  • p

    Patiparn Intaraprasert

    09/23/2021, 9:32 AM
    Looking for some help! Let’s say I’ve schema with many to many relationship A and B with explicit called C. They already have data on both A and B, but not yet at C I want to update the data of A and B into C Q./ Which query method should I use? [set, connect, connectOrCreate, upsert, updatemany, ….]
    r
    • 2
    • 2
  • g

    glekner

    09/23/2021, 2:54 PM
    Why can't I use a
    where
    clause inside a
    _count
    inclusion like this?
    Copy code
    include: {
                _count: {
                  select: {
                    workers: true,
                    tasks: {
                      where: {
                        isCompleted: false,
                      }
                    },
                  },
                },
    }
    t
    r
    • 3
    • 3
  • b

    Bamada

    09/23/2021, 10:12 PM
    Hi everyone, I am using
    Prisma 3.1.1
    with one of my projects. Inside my code, I use the
    rawQuery
    below and I want to type the result of the query.
    Copy code
    const configs = await this.prismaService.$queryRaw<Config[] >`SELECT id, employee_id, start_date, end_date
        FROM configs mc 
            WHERE employee_id IN (${Prisma.join(employeeIds)}) 
            AND DATE_PART('year', mc.start_date) = CAST(${year} AS INTEGER) 
            AND CAST(${month} AS INTEGER) >= DATE_PART('month', mc.start_date)
            AND CAST(${month} AS INTEGER) <= DATE_PART('month', COALESCE(end_date,'2020-12-01'))`;
    
    // generated type
    export type Config = {
      id: number
      employeeId: string
      startDate: Date
      endDate: Date | null
    }
    
    // Expected result
     [Config{id:1, startDate:xxxx, endDate:xx, ..}, ..]
    
    // I got
    [{id:1, start_date:xxxx, end_date:xx, ..}, ..]
    Do you know what’s wrong with my query? I looked at the documentation https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access and I didn’t found my mistake thks
    g
    r
    • 3
    • 8
  • l

    Logan

    09/24/2021, 12:44 AM
    Copy code
    const valid = await client.prisma.invites
          .aggregate({
            _count: {
              inviterId: true,
            },
            where: {
              inviterId: mUser,
              valid: true,
              serverId: message.guildID,
            },
          })
          .catch((e: unknown) => client.logger.error(String(e)));
        const invalid = await client.prisma.invites
          .aggregate({
            _count: {
              inviterId: true,
            },
            where: {
              inviterId: mUser,
              valid: false,
              serverId: message.guildID,
            },
          })
          .catch((e: unknown) => client.logger.error(String(e)));
        const result = await client.prisma.invites
          .groupBy({
            by: ["inviterId"],
            _count: {
              inviterId: true,
            },
            where: {
              serverId: message.guildID,
              inviterId: mUser,
            },
          })
    Hey, just wondering if theres a good way of speeding these query's up? We are using SQL database
  • j

    Jared Fraser

    09/24/2021, 5:58 AM
    Is there plans to support an
    only
    filter for
    1-N
    relations? Currently the options for
    every
    ,
    some
    and
    none
    are limiting. It would be good to query
    Copy code
    children: {
      only: {
        field: "value"
      }
    }
    and it would return children that only match the filter
    r
    • 2
    • 2
  • j

    Jared Fraser

    09/24/2021, 6:00 AM
    essentially the query is
    Copy code
    SELECT *
    FROM parent p
    JOIN children c ON (c.parent_id = p.id)
    WHERE c.field = "value"
  • m

    Martin Nirtl

    09/24/2021, 6:14 AM
    Hi team 👋 is there support for yugabyteDB? it’s a postgres-compatible db, hence i would assume so. still i would like to know if your are maybe running some integration tests?
    r
    • 2
    • 2
1...486487488...637Latest