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

    James L

    05/03/2022, 10:26 AM
    something like:
    Copy code
    const account = await prisma.user.findFirst({
      where: {
        _reqId: 'example-here',
        id: 1,
      },
    });
    then
    Copy code
    const reqIdMiddleware = async (params, next) => {
      if (params?.args?.where['_reqId']) {
        console.log('_reqId was found!', params.args.where['_reqId']);
        delete params.args.where['_reqId'];
      }
      return next(params)
    };
    
    prisma.$use(reqIdMiddleware);
  • j

    James L

    05/03/2022, 10:26 AM
    idk, something dumb like that could work lol. @Ben Ezard
  • j

    James L

    05/03/2022, 10:27 AM
    I think having a
    context
    object on the query methods would be really useful, though.
  • b

    Ben Ezard

    05/03/2022, 11:36 AM
    Interesting idea, thanks @James L Like you said though, probably best to have something actually built into Prisma for this though haha I've raised an issue on GitHub for it here, in case you have any thoughts on a suggested implementation route 🙂
  • j

    James L

    05/03/2022, 11:37 AM
    @Ben Ezard
    There aren't any clean alternatives
    😮
  • j

    James L

    05/03/2022, 11:37 AM
    "what about my alternative wasn't clean???" lol
    b
    • 2
    • 6
  • m

    mikkelsl

    05/03/2022, 4:46 PM
    Does anyone know of any examples of using prisma to create line charts, where you need counts based on f.i. hours 0-24, days 1-31, months 1-12, years 1-5? I've never made this before, and feel like I'm making it more complicated than it probably needs to be.
    n
    • 2
    • 1
  • k

    Kevin McKernan

    05/03/2022, 11:11 PM
    having issues running tests with prisma mocked in jest test, posted related info in the discussion on github: https://github.com/prisma/prisma/discussions/7084#discussioncomment-2683574
    n
    • 2
    • 8
  • h

    Harry

    05/05/2022, 1:20 PM
    Hi, I’m quite new to prisma. Is there any example project using prisma in node.js/express with sqlite? And not sure if I should create the prisma client only once or in each service files?
    a
    n
    • 3
    • 6
  • r

    Ravi Shankar

    05/06/2022, 10:16 AM
    https://github.com/prisma/prisma/discussions/13177 I am getting this
    error
    . can someone help me out in this
    n
    • 2
    • 3
  • n

    Neil Oliver

    05/09/2022, 9:29 PM
    I am wondering if anyone can spot something i am doing wrong or if this is a Prisma issue / limitation. I am trying to run a simple query using
    $queryRaw
    (Prisma Client 3.13.0) with SQLite.
    SELECT value FROM generate_series(5,100,5)
    . (This is just an example from the SQLite docs). Unfortunately I am getting the error
    no such table: generate_series
    . Any input would be appreciated.
    n
    • 2
    • 9
  • k

    Kevin McKernan

    05/10/2022, 1:30 AM
    1. does the table definitely exist 2. did you run a migration?
  • m

    Michael

    05/10/2022, 5:36 AM
    Hi 👋 . Does anyone know where I can find the type information for prisma.$queryRaw? Having trouble annotating the response of raw queries.
    n
    f
    • 3
    • 4
  • j

    Johan LAJILI

    05/11/2022, 4:06 PM
    Hey everyone, sorry if this is a silly question but I can't figure it out from the doc. When you have an array of relations
    Copy code
    model House {
      id String @default(cuid()) @id
      windows: Window[]
    }
    
    model Window {
      house House @relation(fields: [houseId], references: [id])
      houseId: String
    }
    Is the order of the windows array meaningful? I need the user to be able to create a window in the middle of the list. I've tried to use set or connect, specifying in there an array where I've put the window in the correct place in JavaScript. It succeeds, but the order does not seem to change, the new window is added at the end. I can of course add a property index to sortBy in the cards, but that mean that whenever I reorder windows I need to update the index of many windows instead of updating one array, so I would rather avoid it. (I'm using Postgres if that's relevant) Thanks
    a
    • 2
    • 5
  • a

    Andrew Leung

    05/11/2022, 4:53 PM
    Hello all, I’m running into an issue in an enterprise Jenkins environment where it seems trying to reach
    <https://binaries.prisma.sh>
    will hang until an
    ETIMEDOUT
    error during a
    yarn install
    My options are limited, and in parallel trying to figure out the network security on the jenkins env to figure out how to get past this issue, but in the meantime, I’m trying to understand how I can work around this by using Engine environment variables.
    n
    • 2
    • 5
  • m

    Martin Pinnau

    05/12/2022, 8:17 AM
    Hi there, I'm trying to migrate my prisma-1 service with nexus and mongodb to prisma2. One odd thing seems to be that with prisma2 you have to add relations to a non-relational database, which wasn't the case in prisma1. Example: model in prisma1:
    Copy code
    type Email @db(name: "emails") {
        id: ID! @id
        name: String @unique
        emailMessage: EmailMessage
        emailSubject: EmailSubject
        receiverGroup: [Receiver]
        isActivated: Boolean! @default(value: true)
        role: String
        btnName: String
    }
    
    type EmailMessage @embedded {
        id: ID! @id
        messageDe: String
        messageEn: String
    }
    
    type EmailSubject @embedded {
        id: ID! @id
        subjectDe: String
        subjectEn: String
    }
    
    type Receiver @embedded {
        id: ID! @id
        email: String!
        firstName: String
        lastName: String
    }
    This is working perfectly fine with prisma1 (prisma-client-lib 1.34.5). Due to restrictions by nexus-plugin-prisma I'm bound to prisma version 2.23.0 regarding upgrade. With this version I can't use the model as it is, I have to add relation keys to all models (formerly types) listed. Prisma1 seems to be able to handle this internally without secondary keys. How can I achieve this with prisma2 and mongodb ?
    j
    • 2
    • 4
  • m

    Martin Pinnau

    05/12/2022, 10:12 AM
    I'm trying to get embedded documents working with mongodb, using prisma 3.14 and the structure according to the schema provided in the release notes of prisma 3.10 ( https://github.com/prisma/prisma/releases/tag/3.10.0 ). Running a query against the db I get an error telling me
    Copy code
    type EmailMessage { .... error: Model declarations have to be indicated with the `model` keyword`
    my schema:
    Copy code
    model Email {
      id            String @id @map("_id") @db.ObjectId
      name          String @unique
      emailMessage  EmailMessage
      emailSubject  EmailSubject
      receiverGroup Receiver[]
      isActivated   Boolean @default(value: true)
      role          String
      btnName       String
    }
    
    type EmailMessage {
      id        String
      messageDe String
      messageEn String
    }
    
    type EmailSubject {
      id        String
      subjectDe String
      subjectEn String
    }
    
    type Receiver {
      id        String
      email     String
      firstName String
      lastName  String
    }
    What am I doing wrong regarding these embedded documents ? Is there support for embedded document lists but not for embedded documents ?
    n
    • 2
    • 1
  • a

    auser

    05/12/2022, 8:07 PM
    Hey y’all anyone have any experience with the rust client (https://github.com/Brendonovich/prisma-client-rust)?
    n
    • 2
    • 3
  • j

    Johan LAJILI

    05/13/2022, 8:26 AM
    Hi everyone, follow up on https://prisma.slack.com/archives/CCWDULGUW/p1652285161791689 I've updated my schema to have an Index property on each of the window, and when I want to create one in the middle of the list, I run an update on the index of all the windows that need to be incremented by one. But that is slow. like 4125ms slow. Even using nested writes (so all the updates happen in one prisma operation), to update just a dozen object. Is there a better data modelling practice for a collection of Models where the order matter and where I want user to be able to reorder models and insert new one at any part of the list?
    ✅ 1
    j
    n
    • 3
    • 7
  • a

    Anderson da Silva

    05/15/2022, 10:13 PM
    Did anyone succeed in making prisma client work with serverless framework on a mac m1? I am deploying it using Node with Typescript. I keep getting this error…
    Copy code
    Error: Query engine library for current platform "darwin" could not be found.
      You incorrectly pinned it to darwin
      
      This probably happens, because you built Prisma Client on a different platform.
      (Prisma Client looked in "path_to_project/.webpack/service/libquery_engine-darwin.dylib.node")
    this is my schema.prisma file config
    Copy code
    generator client {
      provider      = "prisma-client-js"
      binaryTargets = ["native"]
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    Already tried other binaryTarges, adding bynary target path from my node_modules, nothing worked so far….
    r
    • 2
    • 4
  • i

    iki

    05/16/2022, 9:09 AM
    Hello all 🙌 Any idea, how we can log a failed query in Prisma Client? We have working Prisma Client event logging on GCP via Winston Stackdriver transport, but when we get a
    Query interpretation error [2016]
    , there's no event emitted for logging, the error is just thrown and logged later by Apollo Client, but without any important details like the failing query.
    Copy code
    clientVersion: "2.21.2"
    code: "P2016"
    meta: {
    details: "Error for binding '1': AssertionError("Expected a valid parent ID to be present for nested update to-one case.")"
    }
    stack: "Error: Query interpretation error. Error for binding '1': AssertionError("Expected a valid parent ID to be present for nested update to-one case.")
        at cb (/usr/src/api2/node_modules/@prisma/client/runtime/index.js:34780:17)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:97:5)"
    prisma rainbow 2
  • m

    Martin Pinnau

    05/16/2022, 3:02 PM
    Hi there, is there a new way to set properties of a nexus stringArg to not required ? With prisma1 this was done by
    Copy code
    args: {
            buttonName: stringArg({ required: false }),
          },
    this doesn't work anymore
    d
    • 2
    • 1
  • m

    Martin Pinnau

    05/16/2022, 3:04 PM
    ...also searching for an alternative for
    Copy code
    stringArg({ list: [false] }),
    d
    • 2
    • 1
  • n

    Nico Domino

    05/21/2022, 11:32 AM
    Whats the recommended column type for images? I want to store potentially an image URL and a base64 encoded string. Currently I have it set to
    image      String?      @db.Text
    n
    • 2
    • 2
  • n

    Nico Domino

    05/21/2022, 11:33 AM
    But when I go to update an entry, it always tells me the next column in the schema is too long 🤔 i.e.
    Copy code
    prisma.bookmark.update({
      where: id,
      data: {
        image: imageBase64
      }
    })
    m
    • 2
    • 2
  • n

    Nico Domino

    05/21/2022, 11:33 AM
    Schema looks like this
  • n

    Nico Domino

    05/21/2022, 11:34 AM
    And it throws this error.. I'm logging out the keys of the data object at the top, i.e. the data to update only has an
    image
    key in it. Yet prisma is saying the
    desc
    column isn't long enough for some reason?
  • k

    Kevin Lin

    05/22/2022, 3:27 AM
    hey all, i'm a founder of a developer focused knowledge base and I'm currently researching whether prisma can be embedded into our application. so far, its checking all the boxes - just one holdout i'm hoping folks here can help me with. can a custom prisma client be exported as a npm package so that it can be used as a public facing sdk? our use case: we offer a plain text based knowledge base for developers and the metadata will be stored in sqlite. we have multiple clients (eg. CLI, VSCode, vim) that need to access the metadata - ideally, we can define the prisma model in one place and then export it to all the packages that need it. Basically do something like the following and consume this in a separate package
    Copy code
    ts
    import { PrismaClient } from '@prisma/client'
    export { PrismaClient as DendronClient }
    🔥 1
    j
    n
    • 3
    • 3
  • k

    Kevin Lin

    05/22/2022, 3:27 AM
    any pointers appreciated 🙏
  • b

    Ben Ezard

    05/23/2022, 1:42 PM
    Is there a way to order by relations? e.g. if I have a list of conversations, and each conversation has a list of messages, I'd like to be able to do something like "select the most recent 10 conversations, ordered by the date of the most recent message in each conversation" So I guess this translates to something like
    Copy code
    SELECT * FROM "Conversation" ORDER BY (SELECT "createdAt" FROM "Message" WHERE "conversationId" = "Conversation".id ORDER BY "createdAt" DESC LIMIT 1) LIMIT 10;
    r
    • 2
    • 4
1...1920212223Latest