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

    Adam

    10/19/2021, 8:48 PM
    Hello. I’m totally stuck and confused what I’m doing wrong, maybe you, guys, can help. I’m trying to create record with:
    Copy code
    prisma.role.create({
        data: {
            Id: 1,
            Name: 'Test',
            Description: 'Test',
            IsActive: true,
            CreatedByUser: { connect: { Id: 2 } },
            LastUpdateByUser: { connect: { Id: 2 } },
        },
    });
    and PrismaClient doesn’t allow me to, because of:
    Copy code
    Types of property 'Id' are incompatible. Type 'number' is not assignable to type 'never'.`
    and hinting me about:
    Copy code
    The expected type comes from property 'data' which is declared here on type '{ select?: RoleSelect; include?: RoleInclude; data: (Without<RoleCreateInput, RoleUncheckedCreateInput> & RoleUncheckedCreateInput) | (Without<...> & RoleCreateInput); }'
    and my question is - why PrismaClient doesn’t allow me to use Id for creating? in my model schema I have simply:
    Copy code
    Id                    Int      @id @default(autoincrement())
    Similar result I have with upsert as well. And what is totally weird to me - some models works fine. I already spend 2 hours to figure out why it happens to this particular model. Can anyone help?
    a
    • 2
    • 3
  • m

    Matt Knight

    10/19/2021, 9:23 PM
    Perhaps this is more of a typescript question, but if I have a model like this in Prisma:
    existingListing: Listings & {
    ListingPhotos: ListingPhotos[];
    }
    How do I instantiate (if that is the right word?) it on the client? Normally I would do something like this:
    existingListing: Listings = []
    But with the nested model, it doesn't work.
    a
    • 2
    • 4
  • m

    Matt Knight

    10/19/2021, 9:40 PM
    (I could cast it to
    any
    )
  • j

    Jordan Epps

    10/21/2021, 9:48 PM
    has anyone else noticed that the return type for
    $transaction
    is incorrect? I submitted an issue today.
    r
    • 2
    • 3
  • t

    Taylor Preston

    10/23/2021, 7:45 PM
    Hey! Random question. Is there a way to set a default selection of fields returned from an object? For example. For example if I don’t want to return an
    account_number
    on a user unless I specifically ask for it.
    r
    • 2
    • 2
  • m

    Mischa

    10/27/2021, 11:01 AM
    i'm using prisma with postgresql - it appears to be doing a SELECT then INSERT for simple
    upsert()
    calls. is this correct? created an issue: https://github.com/prisma/prisma/issues/9972
    👀 2
    r
    • 2
    • 1
  • m

    Mischa

    10/27/2021, 11:16 AM
    it's like using a library that has array.quickSort() and when you call it it does a bubble sort 🧐
    ✅ 2
    😅 2
  • t

    Tigran Tokmajyan

    10/27/2021, 4:25 PM
    Any idea why this happens after upgrade from 2.23 to 3.3?
    Copy code
    WARNING in ./libs/prisma/src/lib/client/runtime/index.js 81:73-80
    Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
    
    WARNING in ./libs/prisma/src/lib/client/runtime/index.js 85:15-22
    Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
    Debugger listening on <ws://localhost:59074/bf3dd720-b8d2-4f0e-91c1-d9b4532054a3>
    Debugger listening on <ws://localhost:59075/bf3dd720-b8d2-4f0e-91c1-d9b4532054a3>
    For help, see: <https://nodejs.org/en/docs/inspector>
    
    C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime sync:2
            var e = new Error("Cannot find module '" + req + "'");
    ^
    Error: Cannot find module 'os'
        at webpackEmptyContext (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime sync:2:1)
        at ../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime\index.js:1740:15)
        at __require2 (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime\index.js:89:45)
        at ../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime\index.js:2004:56)
        at __require2 (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime\index.js:89:45)
        at Object../libs/prisma/src/lib/client/runtime/index.js (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\runtime\index.js:30779:33)
        at __webpack_require__ (C:\gits\boon\backend\dist\apps\cron\webpack:\webpack\bootstrap:19:1)
        at Object../libs/prisma/src/lib/client/index.js (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\prisma\src\lib\client\index.js:17:5)
        at __webpack_require__ (C:\gits\boon\backend\dist\apps\cron\webpack:\webpack\bootstrap:19:1)
        at Object../libs/common/src/lib/services/prisma.service.ts (C:\gits\boon\backend\dist\apps\cron\webpack:\libs\common\src\lib\services\prisma.service.ts:2:1)
    r
    • 2
    • 12
  • d

    Devin

    10/28/2021, 4:08 AM
    I’m seeding a db and curious the best practice for informing foreign keys.
    Copy code
    const projects = ["project 1", "project 2"]
    projects.forEach(async (p) => await db.project.create({data: {name: p}})
    
    const dbProjects = db.project.findMany()
    db.task.create({
      data: {
        name: 'some task',
        project: {connect: {id: dbProject.find((p) => p.name.includes("project 1")).id},
    I’m getting TS errors with
    dbProject.find
    because of course it could be undefined… Is there a better way to be thinking about this?
    r
    • 2
    • 2
  • s

    Salvador Lopez Mendoza

    10/28/2021, 5:15 PM
    Question, is there a way to use
    in
    in the where clause of a query where the column data type is a
    string
    which values are like
    1,2
    ? Like
    prisma.model.findMany({ where: { col: { in: [1, 2] } } })
    r
    • 2
    • 2
  • j

    Jarid Margolin

    10/29/2021, 10:56 PM
    Anyone else have issues using prisma stack traces? It shows a tail of internal prisma methods but it never shows the originating call. It makes it really difficult to track down where/why the error surfaced.
    ☝️ 1
    r
    • 2
    • 2
  • n

    Navin

    10/31/2021, 4:14 PM
    Does prisma 2 come out of the box with createdAt / updatedAt properties on entities? If so how do we need to specify this?
    t
    • 2
    • 3
  • s

    sven

    11/02/2021, 9:55 AM
    How to save partial dates with prisma? Prisma supports ISO 8601 which in theory supports it. When only saving a year ‘2021’ I am seeing the following error:
    Copy code
    Argument started: Got invalid value '2021' on [...]. Provided String, expected DateTime or NullableDateTimeFieldUpdateOperationsInput or Null.
    Is it possible to save say ‘2021’ in a date field and then also query it?
    r
    • 2
    • 8
  • t

    Tyler Bell

    11/03/2021, 3:48 AM
    Does anyone know what this error means and how to fix?
    Please note that it is not possible at the moment to have a null-cursor, or a cursor and orderBy combination that not stable (unique).
    In my case, the cursor is not null, so assuming it’s from “a cursor and orderBy combination” My query is…
    Copy code
    prisma.member.count({
      where: {
        app: { id }
      },
      orderBy: {
       createdAt: "desc"
      },
      cursor: {
        id: after_cursor
      }
    })
  • p

    potatoxchip

    11/03/2021, 5:56 PM
    What is the prisma equivalent of mysql's
    INSERT IGNORE INTO ... ;
    ?
    r
    • 2
    • 2
  • m

    Mischa

    11/03/2021, 6:15 PM
    i would be so so happy if the generated client used ES6 import/exports instead of commonjs. it would make my lambda functions so so much smaller! please I beg 🙏
  • n

    Nick Zhang

    11/04/2021, 6:53 AM
    Anyone familiar with this error ?
    t
    • 2
    • 2
  • y

    Yaakov

    11/05/2021, 2:36 PM
    Is there any sort of mapping between Prisma error codes and http response codes? I'm finding myself writing way too many if statements. Perhaps there is a way to capture all server/database related statements so I can respond 500?
    r
    • 2
    • 2
  • g

    Gheorghe

    11/05/2021, 4:47 PM
    Hello everyone, While doing some tests unit tests, trying to create a record with missing information on a required field, I get a ‘PrismaClientValidationError’ object, with ‘message’ filled properly, but no ‘code’ ? According to the error page list the should be an code for this kind of error: => https://www.prisma.io/docs/reference/api-reference/error-reference Does anyone encountered this behaviour in the past ? Thank you ! Context: MacOS BigSur 11.6 “Prisma”: “^3.4.0",
  • y

    Yaakov

    11/08/2021, 3:23 PM
    Is there a way to optionally filter a hasOne relationship? Schema:
    Copy code
    model User {
      id    Int    @id @default(autoincrement())
      name  String
      posts Post[]
    }
    
    model Post {
      id       Int   @id @default(autoincrement())
      author   User? @relation(fields: [authorId], references: [id])
      authorId Int?
    }
    Example #1 Filters out all Posts with a null
    authorId
    if
    req.query.authorName
    is `undefined`:
    Copy code
    router.get('/posts', async (req, res, next) => {
    
      const posts = await prisma.post.findMany({
        where: {
          author: {
            is: {
              name: {
                in: req.query.authorName
              }
            }
          }
        },
        include: {
          author: true
        }
      });
    
      res.json({ data: posts });
    });
    Example #2 If
    req.query.authorId
    is
    undefined
    , it does not filter and returns everything:
    Copy code
    router.get('/posts', async (req, res, next) => {
    
      const posts = await prisma.post.findMany({
        where: {
          authorId: {
            in: req.query.authorId
          }
        },
        include: {
          author: true
        }
      });
    
      res.json({ data: posts });
    });
    Why is there inconsistent behavior between the 2 examples? In example #1, how can I assure that no filter is performed when
    req.query.authorName
    is
    undefined
    ?
    r
    • 2
    • 3
  • m

    Mischa

    11/08/2021, 3:56 PM
    what am I doing wrong here?
    Copy code
    validateUpsertLinkedIn(args: PrismaTypes.CandidateUpsertArgs) {
        return Prisma.validator<PrismaTypes.CandidateUpsertArgs>()(args)
      }
    
    
    packages/repo/src/repository/candidate.ts:22:12 - error TS2615: Type of property 'AND' circularly references itself in mapped type '{ [K in keyof CandidateCommentScalarWhereInput]: K extends keyof CandidateCommentScalarWhereInput ? Exact<CandidateCommentScalarWhereInput[K], CandidateCommentScalarWhereInput[K]> : CandidateCommentScalarWhereInput[K]; }'.
    r
    • 2
    • 1
  • m

    Mischa

    11/09/2021, 3:21 PM
    Anyone else encountering an issue with nodejs lambda where the prisma client doesn’t attempt to reconnect if it failed to connect to the DB? (https://github.com/prisma/prisma/issues/9902)
  • b

    Ben Ezard

    11/12/2021, 11:42 PM
    If I create a nullable relation alongside the main entity, is there a way for it to be marked as non-null when returning it? e.g.
    Copy code
    model Author {
      name String
    }
    
    model Book {
      author Author?
    }
    Copy code
    const book = await this.prismaService.book.create({
      include: {
        author: true,
      },
      data: {
        author: {
          create: {
            name: 'Bob',
          },
        },
      },
    })
    In the above example,
    book.author
    is nullable, yet that the fact that that function succeeded and is returning data means that that field will never be null Is there an existing way to get
    book.author
    back as a non-nullable value, or should I create a feature request on GitHub for this?
    r
    • 2
    • 1
  • b

    Benjamin Smith

    11/13/2021, 10:04 PM
    Is there any documentation on how to make a Prisma plugin/generator? I want to make one but I can't find anything in the docs about how to get started/what APIs are available to use
  • b

    Benjamin Smith

    11/13/2021, 11:30 PM
    Here: https://www.prisma.io/docs/concepts/components/prisma-schema/generators I found this:
    Alternatively you can define any Npm package that follows our generator specification
    But I've looked through all of the docs and can't find this generator specification.
    j
    • 2
    • 1
  • p

    Pinja Jäkkö

    11/17/2021, 12:13 PM
    Copy code
    TSError: ⨯ Unable to compile TypeScript:                                                                               
    src/controllers/charts/discussions.ts:61:26 - error TS2694: Namespace '"[...]/node_modules/.prisma/client/index".Prisma' has no exported member 'validator'.                                           
                                                                                                                           
    61   const messages: Prisma.validator<Prisma.discussionInclude>()({
    Hi, I'm trying to use the validator for the first time but am getting this error.
    r
    • 2
    • 19
  • m

    Mike Willbanks

    11/22/2021, 6:54 PM
    I’m having an odd issue with the documentation not necessarily matching reality… Any help?
    Copy code
    await prisma.model.update({
          where: {
            model_id: {
              not: +model.model_id,
            },
          },
          data: {
            is_archived: true
          },
        });
    errorInvalid `prisma.model.update()` invocation:{where: {model_id: {not: 7}~~~~~~~~},data: {is_archived: true}}Argument model_id: Got invalid value{not: 7}on prisma.updateOnemodel. Provided Json, expected Int
    ✅ 1
    • 1
    • 2
  • d

    Devin

    11/23/2021, 6:03 PM
    Is it possible to rename fields?
    Copy code
    prisma.piranhas.findMany({
      select: {
        name as blipbleepblop
      }
    })
    r
    • 2
    • 1
  • i

    Italo Gama

    11/27/2021, 1:48 AM
    Hi guys, i need some help.. https://stackoverflow.com/questions/70131425/nestjs-prisma-how-to-create-record-with-relational-fields
  • w

    Wingy

    11/27/2021, 5:53 AM
    Copy code
    GalaxyInfo.prisma.$executeRaw`
            CREATE TEMPORARY VIEW "Kill_temp" AS
            SELECT *
            FROM "Kill_clean"
            WHERE
              killer_id IN (${Prisma.join(players)})
          `,
    Copy code
    Your raw query had an incorrect number of parameters. Expected: `0`, actual: `1`.
    Anyone know why I'm getting this? trying to create a temp view with a dynamic where for the rest of my transaction to use
    r
    • 2
    • 2
1...131415...23Latest