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

    Hubert Kowalski

    09/14/2022, 2:38 PM
    Considering such models:
    Copy code
    model Wallet {
      user User
      balance Int
      incomingTransactions Transaction[] @relation("incomingTransaction")
      outgoingTransactions Transaction[] @relation("outgoingTransaction")
    }
    
    model Transaction {
      id Int 
      change Int
      toWallet Wallet @relation(name: "incomingTransaction")
      fromWallet Wallet? @relation(name: "outgoingTransaction")
    }
    how can I create a query that creates the transaction and: 1. decrements balance of fromWallet by
    change
    if specified 2. increments balance of toWallet by
    change
    3. and actually returns Transaction in the end Couldn't figure it out on my own πŸ˜• Should I maybe just opt in to use $transaction?
    βœ… 1
    h
    • 2
    • 1
  • s

    Slackbot

    09/14/2022, 3:28 PM
    This message was deleted.
  • m

    Max Daunarovich

    09/14/2022, 4:52 PM
    Have anyone experienced issues on Windows specifically? One of my tests drops whole app if I make a specific request with one library(blockchain related) and then make call with Prisma Client. This doesn’t happen if you reverse the process - first PC, then fetching lib). Nor does it happen on Mac πŸ€·β€β™‚οΈ I would appreciate any input πŸ™‡πŸ»β€β™‚οΈ
    βœ… 1
    v
    a
    • 3
    • 8
  • a

    Aman Dalmia

    09/14/2022, 5:22 PM
    Hey folks. I have a use-case where I want to sort my values on the basis of relevance. Now, relevance is calculated based on filters. The rows matching more of the filters should be considered more relevant. Ideally, I would like to provide a method to compute this value for each row and add it under a column like
    relevance
    , and then pass
    relevance
    for
    orderBy
    . We are also using pagination. Which is why it is very important to have the sorting bit done using Prisma's native sorting support. Something like this would be ideal:
    Copy code
    this.prisma.job.map((job) => { ...job, relevance: calculateRelevance(job) }).findMany({ orderBy: relevance })
    I tried reading the docs to search for something that might work but couldn't find something to match this use case. Does anyone have any suggestions for how I can go about this? Or do you recommend a different approach?
    πŸ‘€ 1
    a
    • 2
    • 3
  • a

    aetheryx

    09/14/2022, 8:36 PM
    https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#generating-prism[…]k-of-prismaclient is it possible to disable this behavior (the postinstall hook)?
    βœ… 1
    r
    • 2
    • 1
  • c

    Colin Robinson

    09/15/2022, 5:21 AM
    Hey, I'm not having much luck getting prisma (node/express) to read the DATABASE_URL app settings from the azure app service... Does anyone know if it needs any additional packages installed to be able to pull the app setting?
    πŸ‘€ 1
    r
    v
    • 3
    • 2
  • s

    See Jee

    09/15/2022, 6:03 AM
    Hello, I want to implement the Cascade Delete but I don’t know how to implement it in my case. I have 3 tables which is Document, Media and Post
    Copy code
    model Media {
        mediaUid            String                  @id      @db.Uuid
        title               String
    }
    
    model Document {
        documentUid         String                  @id      @db.Uuid
        title               String
    }
    
    model Post {
        postUid             String                  @id      @db.Uuid
        attachedUid         String                           @db.Uuid
        title               String
    }
    The attachedUid in Post table is the uid of Document or Media. When I delete the Media or Document I want to delete it too in Post.
    βœ… 1
    πŸ†˜ 1
    πŸ‘€ 1
    r
    v
    • 3
    • 12
  • k

    Kenny Tran

    09/15/2022, 12:24 PM
    Hey everyone. Nice to meet y'all. I have a question regarding Prisma's $transaction API. I'm currently using it to run two queries sequentially but how many more queries can i add before it becomes a problem. I'm quite new to Prisma πŸ™‚
    βœ… 1
    j
    • 2
    • 11
  • l

    Lucas Reinaldo

    09/15/2022, 12:37 PM
    Hello folks! Quick question, i am using nextjs, supabase postgres and prisma + prisma data proxy but i keep running out of connections, am i missing something ?
    k
    • 2
    • 11
  • t

    Ted Joe

    09/15/2022, 1:53 PM
    When I try connecting a table row to another table, I get the following error:
    Copy code
    Type '{ id: string; }[]' has no properties in common with type 'ProfileTypeWhereUniqueInput'.ts(2559)
    index.d.ts(17294, 5): The expected type comes from property 'connect' which is declared here on type 'ProfileTypeCreateNestedOneWithoutUserInput'
    I have the following tables
    Copy code
    model ProfileType {
      id String @id @default(cuid())
      name     String                  @db.VarChar(255)
      user.    User[]
    }
    
    model User {
      id String @id @default(cuid())
      profileType   ProfileType @relation(fields: [profileTypeId], references: [id])
      profileTypeId String
    }
    Here's where I connect them
    Copy code
    const allProfileTypes = await db.profileType.findMany({
          select: { id: true },
    })
    
    const profileType = allProfileTypes[0]
    await db.user.create({data: profileType: { connect: [{ id: profileType.id }] },})
    What am I doing wrong and how can I fix them?
    βœ… 1
    n
    • 2
    • 8
  • j

    Jamie Higgins

    09/15/2022, 2:16 PM
    Hello guys
    πŸ‘‹ 2
  • j

    Jamie Higgins

    09/15/2022, 2:34 PM
    Got a question I can’t seem to google my way out of, seems quite straightforward I’m trying to do this:
    Copy code
    async function getLatestBuildByTagAndVersion(tag: string, appVersionId: number) {
    const result = prisma.build.findFirst({
      where: {
        component_version: {
          app_version_id: appVersionId,
          git_tag: tag,
          git_sha: "want this from the build.git_sha",
          },
      },
      orderBy: {
        build_number: "desc",
      }
    });
    Essentially I want git_sha to be:
    Copy code
    build.git_sha = component_version.git_sha
    πŸ‘€ 1
    n
    v
    • 3
    • 3
  • x

    Xavier Quelard

    09/15/2022, 3:06 PM
    Hi there ! πŸ‘‹ I was wondering what was the current status of data/imperative/custom migrations for prisma (I’ve seen these three terms used to discuss mostly the same idea : having the ability to have .ts migration files in addition to .sql files) The most recent issue I can find is this one https://github.com/webstudio-is/webstudio-designer/issues/259 It’s tagged as completed, does this mean than in future releases, we can expect this feature? Thanks a lot πŸ™‚
    βœ… 1
    n
    • 2
    • 2
  • a

    Amol Patel

    09/15/2022, 7:35 PM
    Does prisma support composite indices for postgres?
    βœ… 1
    r
    • 2
    • 1
  • c

    Charlie

    09/15/2022, 8:29 PM
    Hello! I’ve just started to look into using Prisma across all my future projects as it offers the migration, seeding and simple but powerful API that I’ve been looking for. But I’m having a lot of trouble with BigInt (I’ve seen a lot of posts about this already) and typing within React/TypeScript projects. I understand that the BigInt to JSON issue seems to be a problem with JavaScript itself not being able to transpose it correctly, Should I instead use Int instead for my DB ID’s? The typing issue comes when I’m trying to share types between backend and frontend (currently using Next.js and API Routes), anytime I transpose the data to JSON most of the types are lost (BigInt, DateTime etc) and I haven’t figured out a way to carry these types across without writing them out, which kinda defeats the purpose of using that feature of Prisma. Would love to hear some thoughts or ideas of how to get around these issues
    πŸ‘€ 1
    a
    • 2
    • 2
  • s

    Samuel Proschansky

    09/15/2022, 10:09 PM
    Hello. I am creating a query with a joined field that has a lot of records and "take" is not speeding up the query whatsoever. What is a good alternate way to limit the number of results and speed up the query?
    d
    • 2
    • 1
  • s

    Samuel Proschansky

    09/15/2022, 10:25 PM
    I can post the query if anyone has a second to look. I have the query running with a queryRaw and am trying to convert to Prisma.
    πŸ‘€ 1
    r
    • 2
    • 8
  • d

    David Hancu

    09/16/2022, 5:26 AM
    πŸ‘‹ Hi everyone! Prisma Util v1.3.0 is going to be released soon with a ton of new features, as well as some improvements to make the
    pg_trgm
    proposal easier to implement. Features added in v1.3.0: β€’ Code-generated schemas β€’ Config is migrating from
    .json
    to
    .mjs
    β€’ Additional ways of configuring Prisma (such as YAML) β€’ Improved internals for handling migrations, to allow you to create
    .ts
    migration files in v1.4.0 and to facilitate
    pg_trgm
    integration with Prisma
    fast parrot 1
    prisma rainbow 2
    prisma cool 1
    πŸš€ 1
    🚒 1
    m
    • 2
    • 2
  • a

    Alex Ruheni

    09/16/2022, 10:08 AM
    New Prisma Blog Post: πŸ‘‰πŸΎ Improving Query Performance with Indexes using Prisma: B-Tree Index One strategy for improving performance for your database queries is using indexes. This article will dive a deeper into B-Tree indexes: taking a look at the data structure used and improve the performance of an existing query with an index using Prisma.
    πŸš€ 4
  • v

    Vasily Zorin

    09/16/2022, 12:03 PM
    It would be really nice to use partial indexes and constraints in pg/cockroach. I don’t like that you now need to edit migration files manually. I want my entire schema to fit in schema.prisma.
    βœ… 1
    r
    • 2
    • 2
  • s

    Sean Templeton

    09/16/2022, 5:45 PM
    Hi everyone! I'm trying out prisma as we are looking to migrate a current application to Next.js with TypeScript, and adding testing to really tighten up the stability of the app. I'm getting really close, but I'm having an issue with typescript throwing an error when trying to mock a
    groupBy
    call. Currently I have this:
    Copy code
    prismaMock.fitment.groupBy.mockResolvedValue([
    	{ year: '2020', make: 'Ford', model: 'F-150', sub_model: null },
    ]);
    πŸ‘€ 1
    a
    v
    n
    • 4
    • 11
  • s

    Sean Templeton

    09/16/2022, 5:45 PM
    Typescript is complaining though:
    TS2322: Type '{ year: string; make: string; model: string; sub_model: string; }' is not assignable to type 'PickArray<FitmentGroupByOutputType, FitmentScalarFieldEnum[]> & { _count: true | { id?: number | undefined; ... 26 more ...; _all?: number | undefined; } | undefined; _avg: { ...; } | undefined; _sum: { ...; } | undefined; _min: { ...; } | undefined; _max: { ...; } | undefined; }'. Type '{ year: string; make: string; model: string; sub_model: string; }' is missing the following properties from type 'PickArray<FitmentGroupByOutputType, FitmentScalarFieldEnum[]>': id, created, modified, available, and 19 more.
  • s

    Sean Templeton

    09/16/2022, 5:46 PM
    Another error i'm seeing is this:
    Argument type {sub_model: string, year: string, model: string, make: string}[] is not assignable to parameter type ResolvedValue<unknown>
  • s

    shahrukh ahmed

    09/16/2022, 6:10 PM
    I have a weird issue that I can't get my head around. Basically, I have a URL with a parameter
    transaction_id=22596059218
    . Now I want to update this into a Prisma integer field. I convert the query parameter string to an integer with
    transactionId = parseInt(transaction_id)
    and update
    Copy code
    await prisma.user.update({
    		where: { id: userId },
    		data: {
    			transactionId,
    		}
    	})
    The weird bit is, when I check in Prisma studio, the value for
    transactionId
    is
    1121222738
    . Anyone have an idea?
    βœ… 1
    r
    • 2
    • 2
  • b

    Bryan Z

    09/16/2022, 6:36 PM
    Hi everyone, I'm getting an `Invalid
    prisma.tagRank.create()
    invocation:`when running my app in a docker container but the error doesn't appear when running in local dev and build modes. Is there a way to get a more detailed log of which part of the .create() invocation is invalid? (ie. is it a syntax problem, arguments the wrong type etc) Thanks.
    βœ… 1
    r
    j
    • 3
    • 13
  • d

    Dwayne Yuen

    09/16/2022, 9:10 PM
    does prisma batch findFirst calls like it batches findUnique? https://www.prisma.io/docs/guides/performance-and-optimization/query-optimization-performance#solving-n1-in-graphql-wit[…]que-and-prismas-dataloader
    βœ… 1
    n
    • 2
    • 1
  • v

    Valentin Micu

    09/16/2022, 9:59 PM
    Hi team, I’m having a great issue after prisma integration with nextjs
  • v

    Valentin Micu

    09/16/2022, 10:01 PM
    everything works just fine on local env, but once deployed on vercel, I get 500 internal error for that api route
    r
    • 2
    • 1
  • v

    Valentin Micu

    09/16/2022, 10:02 PM
    Any help is highly appreciated, I can’t seem to make it work
  • s

    Samuel Corsi-House

    09/16/2022, 10:16 PM
    Copy code
    ❯ yarn prisma generate
    Environment variables loaded from .env
    Prisma schema loaded from prisma/schema.prisma
    npm ERR! code EUNSUPPORTEDPROTOCOL
    npm ERR! Unsupported URL Type "patch:": patch:@trivago/prettier-plugin-sort-imports@npm%3A3.3.0#~/.yarn/patches/@trivago-prettier-plugin-sort-imports-npm-3.3.0-b578e89971.patch
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/xenfo/.npm/_logs/2022-09-16T22_07_41_297Z-debug-0.log
    Error: Command failed with exit code 1: npm install @prisma/client@4.3.1
    Why is Prisma trying to use NPM when I used Yarn to execute?
    βœ… 1
    k
    • 2
    • 3
1...621622623...637Latest