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

    Wingy

    11/27/2021, 5:53 AM
    thanks!
  • b

    Benjamin Smith

    11/29/2021, 2:36 AM
    Not entirely sure if this is the right channel, but is there a way to have a multi-line string or multi-line comment in a Prisma schema? I'm building a generator and I want to be able to pass in a string with configuration options like this:
    Copy code
    generator myThing {
        provider = "node ./dist/index.js"
        config = `
    my config goes here
    it is multiple lines
        `
    }
    Or like this if necessary:
    Copy code
    generator myThing {
        /**
    my config goes here
    it is multiple lines
        */
        provider = "node ./dist/index.js"
    }
    But I can't figure out a way to do it. Right now the best option seems to be to have a separate docstring comment for each line, but that gets annoying to type if there's a lot of lines:
    Copy code
    generator myThing {
        /// my config goes here
        /// it is multiple lines
        provider = "node ./dist/index.js"
    }
    r
    • 2
    • 2
  • m

    Mischa

    11/29/2021, 11:33 AM
    I don't suppose there is any ETA on supporting
    ON CONFLICT ...
    for upserts?
    r
    • 2
    • 1
  • a

    Anton Reindl

    12/01/2021, 2:31 PM
    Hi Prisma-Users! I have very basic question on how to create joins the PRISMA-way. I did not find a clear guidance in the docs: Imagine the ER in the attachment. We have
    areas
    and
    epics
    . An
    area
    has many
    epics
    and they are related through an
    areaId
    on epics. I have a controller method
    area/<area-uid>/epics
    in my API. What’s the best way to get all epics for a given area ? I tried two ways: 1. Two function calls
    Copy code
    const area = await this.findOne(uid)
    return this.prisma.epic.findMany({ where: { area } })
    --> this creates two independent SQL quereies 2. One function call
    Copy code
    return (await this.prisma.area.findUnique({ where: { uid }, select: { epics: true } }))['epics']
    Works, but feels quirky. --- Is there a better solution? Like a simple right join? Thanks for feedback. I am sure this is a rookie thing. Cheers Anton
    m
    n
    • 3
    • 11
  • n

    nikos l

    12/01/2021, 2:35 PM
    hello, I would like to kindly ask if there is a way to apply a helper method when you try to get nested data with a relational db. the helper method applies some data transformation
    Copy code
    return this.prisma.test.findUnique({
      where: {
        id: params.id,
      },
      include: {
        test1: {
          include: {
            test2: transformationHelper()
          }
        }
      }
  • n

    nikos l

    12/01/2021, 2:36 PM
    it seems something like that ^, possibly there is a better approach
  • s

    Shane

    12/02/2021, 1:50 PM
    Is there an efficient way to do a bulk upsert? ultimately I would like to do a
    createMany
    -- but there is a chance that some rows will duplicate on unique constraint. In those cases I'd like it to just be graceful eg. skip that row or update etc. The best idea i have is to run many concurrent upsert operations, but this could be very inefficient with thousands of rows.
  • s

    Shane

    12/02/2021, 1:50 PM
    Anyone have a better idea?
  • s

    Shane

    12/02/2021, 1:52 PM
    I thought about simply removing those rows first (not ideal), but then there is no way to efficiently remove them either 😅 (as far as I know) without running many concurrent delete operations
  • j

    james tan

    12/02/2021, 2:35 PM
    hi guys, im very curious, did prisma did not ever have hooks like oncreate or beforecreate or beforeupdate or afterupdate or before/afterDelete?
    v
    • 2
    • 2
  • m

    Mischa

    12/02/2021, 6:37 PM
    setting
    log: ["query"]
    is nice and helpful to print out the SQL queries, is there a way to print out the values along with the placeholders when it executes the query?
  • a

    Aaron Waller

    12/03/2021, 6:31 AM
    How to add a new field to a Prisma Model? I asked the full question on stack: https://stackoverflow.com/questions/70210307/how-to-add-a-field-to-a-model-in-prisma-graphql This has to be the simplest thing you can do in Prisma but I still manage to get errors, why is Prisma so complicated?
  • m

    Mischa

    12/03/2021, 4:01 PM
    in JS when I do a query that fails because of a missing column, I don’t see any exception or error message instead the lambda just hangs until timeout. is this a known issue?
  • g

    Garrett Tolbert

    12/04/2021, 3:33 AM
    When I use the
    upsert()
    method as a
    findorCreate
    implementation, I get
    { count: 0 }
    . This is only happening when a user is already in the database. Can someone tell me why this is happening? Below is a snippet of the method call.
    Copy code
    const user = await prisma.user.upsert({
    	where: { email: profile.emails[0].value },
    	update: {},
    	create: {
            email: profile.emails[0].value,
    		name: profile.displayName,
    	},
    });
    l
    • 2
    • 1
  • l

    Luke Carr

    12/05/2021, 5:08 PM
    Does anyone have an efficient way to implement hashids with Prisma? We have a schema that uses autoincrementing IDs throughout but would like to use hashids to encode/decode IDs when they become "public facing". Right now, we have a rather hacky internal library that tracks all of our known ID property names and encodes/decodes them using hashids.
    v
    • 2
    • 1
  • r

    Ryan O'Shea

    12/06/2021, 1:45 PM
    Hi everyone, Entry level dev with an easy one 🙂 I'm missing something about how
    ?
    this works with a relation, or in general. I have a model
    Issue
    with a field
    assignedTo
    that takes a relation
    User?
    as an optional field.
    Copy code
    model Issue {
      id          Int      @id @default(autoincrement())
      createdAt   DateTime @default(now())
      title       String
      description String
      createdBy   User     @relation(name: "createdByUser", fields: [createdById], references: [id])
      createdById Int
    
      assignedTo   User? @relation(name: "assignedTo", fields: [assignedToId], references: [id])
      assignedToId Int?
    }
    However, I can't seem to find a way to write a query to
    create
    or
    update
    that doesn't demand an
    Int
    at
    assignedTo
    without the query failing. For example, the query below won't work unless there is an
    Int
    at
    input.isssue.assignedTo.id
    .
    Copy code
    const newIssue = await db.issue.create({
          data: {
            title: input.issue.title,
            description: input.issue.description,
            createdBy: {
              connect: {
                id: ctx.session.userId,
              },
            },
            assignedTo: {
              connect: {
                id: Number(input.issue.assignedTo.id),
              },
            },
          },
        })
    I tried passing in
    null
    and
    undefined
    directly but both are rejected by the schema. Or should there be separate create and update queries for optional fields?
    Copy code
    if(input.issue.assignedTo.id) { createIssueWithAssignedUser()}
      else {createIssue()}
    m
    l
    • 3
    • 6
  • m

    Matthew Hinton

    12/06/2021, 3:52 PM
    Hello, I am new to prisma and I am trying to get a basic new model to work but any operation on it errors out with
    Field does not exist on enclosing type.
    I am using prisma version 3.6 with this schema definition.
    Copy code
    model KeepAlives {
      id       Int      @id @default(autoincrement())
      tfield   String
      seededAt DateTime @default(now())
    
      @@map("keep_alives")
    }
    I get the error when trying to execute this line:
    *const* keepAliveArr *=*
    *await* prisma.keepAlives.findMany()
    .
    n
    • 2
    • 5
  • l

    Lukáš Stuchlík

    12/06/2021, 8:36 PM
    Hello, is it possible to write some sort of "smart update" query?
    ra-data-prisma
    plugin for React Admin (to connect with Nexus backend) does a thing where you supply new and previous data, it compares them field-wise and only sends a GQL request with setting only new values. So if I have an object
    { id: 1, name: 'John', lastName: 'Doe' }
    and I pass a new object
    { id: 1, name: 'John', lastName: 'Smith' }
    it automatically sends a query like
    { lastName: { set: 'Smith' } }
    and doesn't touch any unchanged fields. Do we have anything like this in Prisma? Or is the "unnecessary update" overhead negligible?
    • 1
    • 1
  • j

    james tan

    12/08/2021, 7:02 AM
    hi guys, anyone using prisma with planetscale? im getting some very cryptic error, wondering if anyone have similar issues with planetscale
    Copy code
    await this.prisma.invoiceItems.create(
      Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 3140, message: "target: unigate.-.primary: vttablet: (errno 3140) (sqlstate 22032) (CallerID: unsecure_grpc_client): Sql: \"insert into InvoiceItems(id, invoice_id, item, paid, accepted_coins, createdAt, currency, updatedAt, amount, paid_amount) values (:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10)\", BindVars: {}", state: "22032" })) })
    m
    • 2
    • 3
  • o

    Okamikun

    12/09/2021, 2:53 AM
    Hi guys, I am currently having the following problem and hope you can point me to the right direction. I have a Lambda function that among other things writes to my AWS RDB database. This is working fine except for the case when one of the non-nullable input variables is null. My understanding is that in this case Prisma would throw an error. But it just hangs and the Lambda function times out after 60 seconds as follows (taken from AWS Cloudwatch logs) without any other error or notice:
    Copy code
    2021-12-09T02:11:42.536Z 38e30598-f091-5333-936d-5fb3975e21d6 Task timed out after 62.06 seconds
    Is that normal behavior or do I need to change my settings so that an error is thrown by Prisma? This is my table definition:
    Copy code
    model tbl_Log {
      id Int @id @default(autoincrement())
      type LogType
      message String?
      createdAt DateTime
      user tbl_User @relation(fields: [userId], references: [id])
      userId String
      orderSnapshot Json
      amount Float
    }
    And I am creating the DB entry via:
    Copy code
    await prisma.tbl_Log.create({
          data: {
            type: log.type!,
            message: log.message!,
            createdAt: log.createdAt!,
            userId,
            orderSnapshot: log.orderSnapshot!,
            amount: log.amount ?? 0,
          },
        });
    If
    amount
    is
    null
    , the Lambda function hangs at this step, if
    amount
    has a
    number
    it works (with 0, too).
    m
    • 2
    • 5
  • y

    Yaakov

    12/09/2021, 3:56 PM
    Is there a way to mix a raw statement into a Prisma Client operation?
    t
    • 2
    • 1
  • j

    Jonathan Gotti

    12/10/2021, 10:41 AM
    Hi there, is there a type i can use for specifying a method return type where I use a findUnique with dinamyc include options passed in. For Example let's imagine i want a function that always add comments when i try to find a post:
    Copy code
    function getPost(postId: string, includeDef: Prisma.PostInclude) Promise<Post> {
      const include = {
        ...includeDef,
        comments: true
      }
      return await this.prisma.post.findUnique({
        where: {id: postId},
        include
      })
    }
  • j

    Jonathan Gotti

    12/10/2021, 10:45 AM
    The problem is if i call it this way
    Copy code
    const post = getPost(postId, {owner: true})
    // trying to do something with post.owner will cause typescript to complain that property owner doesn't exist
  • j

    Jonathan Gotti

    12/10/2021, 10:45 AM
    what type can i use instead of Promise<Post> to make it work properly ?
  • v

    Vladislav

    12/10/2021, 6:16 PM
    Hello everyone. How to change toExpNeg in a Decimal type field by default. For me, when the value is 0.00000002, 2e-8 is returned
  • m

    Mischa

    12/14/2021, 2:05 PM
    Is there any way to reduce the dependency size of prisma in my lambda functions? 7.5MB of minified JS is causing some brutal cold starts
    n
    • 2
    • 14
  • r

    Roryl

    12/17/2021, 9:57 PM
    hi, I'm looking at migrating our plain SQL database driver to prisma for the type safety, one question so far - can Prisma Client work properly with a partitioned table in postgresql? i've seen this github issue about this issue, where one of the prisma folk says it's "probably" transparent for the prisma client, but I'm not sure what this actually means
    • 1
    • 1
  • j

    juanloco

    12/19/2021, 3:35 PM
    Hi all — quick question, If I wanted to write an object typed with a prisma model into a
    JsonObject
    , E.G: see below. How would I do this if the model includes dates? I am currently getting an error due to a type mismatch since a JSON object doesn’t accept date values? but a date should just be parsed to a string I believe, do I need to do this manually so TS won’t complain?
    Copy code
    model User { // user schema here}
    
    import { User } from '@prisma/client';
    
    const myObject: User = prisma.user.findUnique(// query here);
    
    prisma.modelWithJsonField.create({
      data: { jsonField: myObject }
    });
  • j

    Jay Bell

    12/23/2021, 4:53 PM
    Hey all! Has anyone had success running Prisma on AWS Graviton EC2 instances? What binrary target do I need to use for the engine? We currently have these options set:
    Copy code
    binaryTargets = ["native", "linux-musl", "linux-arm-openssl-1.1.x"]
    but then once we deploy to AWS we get
    Copy code
    Error: Unknown PRISMA_QUERY_ENGINE_LIBRARY undefined. Possible binaryTargets: darwin, darwin-arm64, debian-openssl-1.0.x, debian-openssl-1.1.x, rhel-openssl-1.0.x, rhel-openssl-1.1.x, linux-arm-openssl-1.1.x, linux-arm-openssl-1.0.x, linux-musl, linux-nixos, windows, freebsd11, freebsd12, openbsd, netbsd, arm, native or a path to the query engine library.
    We are using Prisma 3.0.1, I know this is older we cannot upgrade (without some more investigtion) because of this issue https://github.com/prisma/prisma/issues/10512 We have multiple prisma schemas in our Nx repo and upgrading to the newest prisma seems to break them. cause it is looking in a hard coded spot for the schema. Ideas?
  • s

    Sabin Adams

    12/23/2021, 9:37 PM
    Is there a way to set up a relation with a table using a non-unique key? Trying to find a way to avoid writing this as two separate queries and I don't have say in changing the existing database.
    Copy code
    const entityStates = await this.prisma.entityState.findMany({
        select: { id: true, entityTypeID: true },
        where: {
            name: state
        }
    })
    
    
    const entityTypes = await this.prisma.entityType.findMany({
        select: { id: true },
        where: {
            name: 'Enrollment',
            id: { in: entityStates.map( state => state.entityTypeID ) }
        }
    })
    The logic I'm looking for would look something like this
    Copy code
    const entityTypes = await this.prisma.entityType.findMany({
        select: { id: true },
        where: {
            name: 'Enrollment',
            EntityStates: {
                where: {
                    name: state
                }
            }
        }
    })
    d
    • 2
    • 2
1...141516...23Latest