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

    Alban Kaperi

    10/20/2022, 2:05 PM
    I have data that are within that range
  • a

    Alban Kaperi

    10/20/2022, 2:05 PM
    should i pass the dates in a different way?
    c
    n
    • 3
    • 9
  • d

    Dan Calise

    10/20/2022, 2:45 PM
    Could anyone help me understand why my
    $queryRaw
    does not work?
    Copy code
    code: 'P2010',
      clientVersion: '4.3.1',
      meta: { code: 'N/A', message: 'N/A' },
    I just get N/A for code/message
    👀 1
    v
    n
    • 3
    • 10
  • z

    Zack Chapple

    10/20/2022, 3:40 PM
    Good Day folks, looking at a few of the issues around Nx, this one in particular is kind of close. We're working on a lot of projects that are leveraging shared modules which are wrapping functionality to be federated or reused. Basically what we're trying to figure out, which does not appear to be supported yet, is to have multiple application level prisma.seeds that we can use to deploy independent applications, but those seeds need to import shared tables and relationships from modules that are either in the nx workspace or from modules that are installed via NPM. These shared modules would be common things like User Management for example. Has anyone seen something like this being done in an official / unofficial capacity. My searches on docs and GH issues didn't yield anything exactly matching what we're trying to do.
    r
    • 2
    • 14
  • d

    David Stotijn

    10/20/2022, 6:13 PM
    Does anybody know if it’s possible (without a raw query) to use “tuple comparison” (I don’t know what it’s called) with Prisma? E.g. something that results in:
    Copy code
    select * from "foobar"
    where ("foo", "bar", "baz") > ('lorem', 'ipsum', 'dolor')
    r
    • 2
    • 9
  • s

    Sebastian Gug

    10/20/2022, 6:41 PM
    would you expect a prisma migration to use up a lot of memory? my cloud run container seems to have failed after using over 512mb 2048mb did the trick
    👀 2
    n
    • 2
    • 2
  • e

    Elias Wambugu

    10/20/2022, 7:48 PM
    I keep running into this problem when I try to do
    prisma migrate dev
    Copy code
    Migration `20220609015525_test` failed to apply cleanly to the shadow database.
    Error:
    db error: ERROR: type "citext" does not exist
    ✅ 1
    j
    • 2
    • 15
  • r

    Ray Tiley

    10/20/2022, 10:38 PM
    is there a way to see all referencees in vs code from prisma schema?
  • r

    Ray Tiley

    10/20/2022, 10:38 PM
    I realize prisma schema generates the actual client.... but I wanna see everywhere in the code a specific model's property is used
    👀 1
    n
    v
    • 3
    • 7
  • t

    Takeo Kusama

    10/21/2022, 4:45 AM
    I wrote it in random channel. But I want to ask prisma client dev team.
    @db.Date
    (at least postgresql) type currently inevitably go wrong if using the other timezone not UTC on the server due to two problems. First, prisma can’t keep timezone information with cut off
    @db.Date
    when storing the data. Further worse, it uses UTC after conversion, thus if user intend to input date as user’s local timezone, it must be forward off by one day and it’s impossible to repair them if contaminating with correct date due to lack of offset by the cut off when local timezone is earlier UTC time. Second, when restoring javascript’s date object, it must need offset because db stores UTC: 000000 time. It’s not identical date by timezone, then users must convert it to their timezone 000000. Otherwise, the server with local timezone later UTC force the date forward off by one day. But prisma client seem not implement this. The two problems leads to 100% bug if using any timezone except for UTC and dangerous if users don’t know that. I suggest simple patch to adjust in the issue in repo. This patch can be used as long as user db stores date as utc: 000000 (though when not cutoff time or prisma will support db stores local time, the logic needs to be skipped). I can fix it with patch only in my code, but this is prisma’s bug, and no one can use appropriately
    @db.Date
    without the patch or living in GMT. If prisma can patch this, the patch in my code must be removed. So can I have the way to tell prisma dev team the fact and ask to fix it?
    v
    • 2
    • 3
  • n

    nikandroid2013

    10/21/2022, 8:28 AM
    Hi there, I have a certain question about using Prisma with Nestjs I followed this guide https://www.prisma.io/nestjs And I log every time it’s making DB connection and it seems to happen on every module init (that’s like onModuleInit works), I wonder if it doesn’t produce a lot of unused connections?
    j
    r
    • 3
    • 12
  • a

    Anton Johansson

    10/21/2022, 12:04 PM
    I know I've asked this before, but I think I need more help. I have an application that needs to work with two different schemas. So I want to generate two different Prisma clients. I also want to re-use these Prisma clients in different projects. So there are two problems: • How can I create NPM packages of my Prisma clients in a good way? I can't just generate the Prisma client and publish, because then I get "wrong" engine binary. Would I need to generate one library for each client? Any other options? We have people working with Mac, Windows and Ubuntu, and also we're running Alpine in production. • How can I make sure both my clients share the same engine binary? I wouldn't want my two libraries to have their own engine binary, since they are relatively large. Is there a way to point to a directory/module where the binary exists? Sorry if my questions are difficult to understand. Has anyone done anything similar to this?
    t
    r
    • 3
    • 4
  • m

    Marek Brzeziński

    10/21/2022, 2:11 PM
    Hi all, I want to create a sports database and I am stuck at Team relations - I would like to separate
    home
    and
    away
    teams in
    Match
    model. Is it even possible to have a relation field that keeps relations to 2 different fields on the other model?
    Copy code
    model Team {
      id           Int     @id @unique
      name         String  @unique
      teamName     String
      locationName String
      website      String
      League       League  @relation(fields: [leagueId], references: [id])
      leagueId     Int
      Match        Match[] // <- THIS ONE IS PROBLEMATIC
    }
    
    model Match {
      id         String   @id @default(cuid())
      apiId      String
      gameDate   DateTime
      season     String
      League     League   @relation(fields: [leagueId], references: [id])
      leagueId   Int
      homeTeam   Team     @relation("Home team", fields: [homeTeamId], references: [id])
      awayTeam   Team     @relation("Away team", fields: [awayTeamId], references: [id])
      homeTeamId Int
      awayTeamId Int
    }
    👀 1
    ✅ 1
    j
    n
    • 3
    • 6
  • r

    Richard Kaufman-LĂłpez

    10/21/2022, 6:18 PM
    I’m looking for a way to define a select statement and then use it in multiple places. For example:
    Copy code
    const userSelect: Prisma.UserSelect = {
        id: true,
        name: true,
    }
    
    const user = await prisma.user.findUnique({
        where: { id: 1 },
        select: userSelect
    })
    
    const posts = await prisma.post.findMany({
        where: { authorId: 1 },
        select: {
            id: true,
            user: {
                select: userSelect
            }
        }
    })
    However, this isn’t working properly. When using
    userSelect
    in the queries, the queries know
    userSelect
    is of the expected type (
    Prisma.UserSelect
    ), but it doesn’t know which fields have actually been selected. This ends up typing both
    user
    and
    posts.user
    to be
    {}
    . A different approach would be to instead write
    userSelect
    like this:
    Copy code
    const userSelect = {
        id: true,
        name: true,
    } as const;
    That works in the query and correctly types the query result. However, now I lose type safety and autocomplete in the definition of
    userSelect
    . Can someone think of a solution that would work correctly in the query select property, the query result, and that would also allow type safety in the definition of the select object?
    ✅ 1
    v
    • 2
    • 3
  • l

    Loren Siebert

    10/21/2022, 7:36 PM
    How can I get the underlying table name associated with a model instance? For example, if I have
    const a = client.accounts.findFirst(…)
    , is there a way I can find out the table name
    Accounts
    from
    a
    ? Something like
    a.tableName
    ? Sort of related to this issue.
    ✅ 1
    r
    • 2
    • 3
  • c

    ChanceAlert

    10/21/2022, 10:46 PM
    Hi, I want to add referential actions to my database so that when I delete a user, I also delete an associated
    profile
    as well as
    cognitoUser
    . I learned that in order to do this, I have to add an
    onDelete: Cascade
    property to the
    @relation
    of the dependent table. Now, my schema looks as the following:
    Copy code
    model User {
      id                   String                   @id @default(uuid())
      cognitoUser          CognitoUser?             @relation(fields: [cognitoUserSub], references: [sub])
      profile              Profile                  @relation(fields: [profileId], references: [id])
    }
    
    model CognitoUser {
      sub            String    @id
      user           User?
    }
    
    model Profile {
      id        String    @id @default(uuid())
      user      User?
    }
    I now have three questions: 1. I want to do the cascading deletes. Did I choose the wrong side (table) to store the foreign key for both
    profile
    and
    cognitoUser
    ? 2. If I did choose the wrong side(s), how can I switch the foreign key to the
    Profile
    and
    CognitoUser
    tables?
    👀 1
    r
    • 2
    • 2
  • c

    ChanceAlert

    10/21/2022, 10:50 PM
    3. What exactly is the difference between "Referential integrity" and "Referential actions"? The documentation is not fully clear on that. The way I understood it, "Referential integrity" is just a mechanism provided by Prisma to achieve a subset of the features of "Referential actions" if that isn't supported by the database itself. Is this correct?
    👀 1
    r
    • 2
    • 1
  • s

    Songkeys

    10/22/2022, 2:59 PM
    I’m confused by this breaking change introduced in 4.5.0: https://github.com/prisma/prisma/issues/15655 What if I want onUpdate and onDelete do nothing? The
    NoAction
    seems useful to me.
    r
    j
    • 3
    • 34
  • d

    David Hancu

    10/23/2022, 10:08 AM
    Hi everyone! I'm currently using
    @Unsupported
    along with
    @default(dbgenerated())
    to create a
    TSVECTOR
    . This method works great, because it edits the migration to generate the
    TSVECTOR
    using
    GENERATED ALWAYS AS
    . But, whenever I try to use this migration, Prisma decides out of the blue to create a migration with just one faulty line that causes an error:
    Copy code
    -- AlterTable
    ALTER TABLE "<Table>" ALTER COLUMN "<Column>" DROP DEFAULT;
    And of course, because it is a generated column, I get this error:
    Copy code
    Database error code: 42601
    
    Database error:
    ERROR: column "<Column>" of relation "<Table>" is a generated column
    HINT: Use ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION instead.
    I've seen the GitHub issues for this and none have fixed my issue. Is there any workaround for this?
    k
    • 2
    • 1
  • j

    Jinhyuck Cha

    10/23/2022, 11:01 AM
    Hi everyone! I'm newbie of prisma, and previously I use TypeORM. I try to use where clause in delete api. I think it is problem of the unique index...
    this is my schema
    Copy code
    model author {
      id          String        @id()
      first_name  String
      second_name String  
      description String?
    
      @@unique([first_name, second_name])
    }
    this is what i want to use in query
    Copy code
    prisma.datasets.delete({
      where: {
        id: datasetId,
        first_name: 'kim'
      }
    But in real, i must put into second_name in where clause
    Copy code
    prisma.datasets.delete({
      where: {
        id: datasetId,
        first_name_second_name: {
          first_name: 'kim',
          second_name: 'sonny'
        }
      }
    })
    I want to partially use where clause in update, delete api!!!!
    👀 1
    ✅ 1
    j
    r
    • 3
    • 5
  • r

    Rafo

    10/23/2022, 11:29 PM
    Hi everyone, I'm new to prism and I'm trying to build a simple ecommerce, but I found it hard to make these relationships.
    👀 1
    r
    • 2
    • 3
  • j

    Jinhyuck Cha

    10/24/2022, 1:14 AM
    Prisma have exist API? Or I just only use
    findFirst()
    API?
    ✅ 1
    j
    • 2
    • 7
  • j

    Jinhyuck Cha

    10/24/2022, 2:05 AM
    Hi! I have question about
    findUniqueOrThrow()
    I try to use it in try-catch clause But the error code not show!!! it just weired, cause the docs said they throw error code and message!
    this is my code
    Copy code
    try {
          const dataset = await this.prisma.datasets.findUniqueOrThrow({
            where: {
              tenant_id: tenantId,
              id: datasetId,
            },
          });
        } catch (e) {
          console.log(e);
          if (e instanceof Prisma.PrismaClientKnownRequestError) {
            prismaQueryFailedError(e);
          }
          throw e;
        }
    this is error code
    Copy code
    NotFoundError: No datasets found
        at /Users/chacha/workspace/dingo/apps/core-api/node_modules/@prisma/client/runtime/index.js:30377:13
  • c

    Chris Tsongas

    10/24/2022, 3:19 AM
    I saw on the pnpm website that Prisma is a sponsor, I presume this means that Prisma works with pnpm, which I haven't tried yet...is anyone using Prisma with a pnpm monorepo?
    🙌 1
    💬 1
    j
    • 2
    • 1
  • d

    David Van Isacker

    10/24/2022, 6:10 AM
    Hi everyone, i noticed the timing for my "prisma.table.create and the actual query are completely different. The actual db insert lasts 1ms from the prisma logs while putting a timer around the create function shows it takes 7-8ms. (15ms for an upsert!). Is this normal and is there a workaround ?
    👀 1
    j
    • 2
    • 1
  • r

    Reo Yamashita

    10/24/2022, 8:48 AM
    Hello, I have a question about update method on Prisma. For example, I have three table below
    Copy code
    model User {
      id         String
      firstName  String       @db.VarChar(100)
      lastName   String       @db.VarChar(100)
      teams      TeamMember[] @relation(name: "user")
      updated_at String
    
      @@id([id])
    }
    
    model Team {
      id         String       @default(uuid()) @db.Uuid
      name       String       @db.VarChar(30)
      members      TeamMember[]  @relation()
    
      @@id([id])
    }
    
    model TeamMember {
      id         String   @default(uuid()) @db.Uuid
      user       User  @relation(name: "user", fields: [userId], references: [id])
      team       Team     @relation(fields: [teamId], references: [id])
      userId     String
      teamId     String   @db.Uuid
      role       TeamRole @default(Admin)
      assignedAt String
    
      @@id([userId, teamId])
    }
    I want users to update a team. especially , Only user who belongs to the team can update the team. how should I code with Prisma?
    ✅ 1
    j
    • 2
    • 10
  • d

    David Hancu

    10/24/2022, 10:49 AM
    Hi everyone! Prisma Util v1.4.0 has finally got a definitive list of features. What will be added in v1.4.0: • (Pre/Post)-migration hooks, allowing you to run JS functions on your migrations! (as well as an API to modify those migrations without the need to write raw SQL, but you'll be able to insert raw SQL if you wish so. This API will provide comments to differentiate different files and other sweet quality of life features.) • Attribute functions for
    @default
    , allowing you to create JS functions that will be ran when a new row is inserted to allow you to customize the ID structure. (The way this will work is that the function will take the DMMF data as an argument and you are expected to return a result. To make this clearer, a proposal will be created soon, so stay tuned for that.) • Add a flag which runs migrations with
    CREATE TABLE UNLOGGED
    instead of
    CREATE TABLE
    (will be implemented under
    --unlogged-tables
    ) •
    Prisma.EnumName
    counterpart for
    Prisma.ModelName
    , to facilitate development by providing a list of enums currently available • Allow refined TypeScript types for fields. For instance you might want to allow only a specific subset of Strings on a field. (Since this feature is more complex, a proposal will be created for it.) This feature is inspired from this issue: https://github.com/prisma/prisma/issues/15742 That is all for this release, I've filtered out what people wanted and have scheduled a few features for v1.5.0 as well. But that list isn't finished yet and it's going to have to wait until this version is released, so let me know what else you'd like to see in Prisma.
    👀 1
    👍 1
    prisma rainbow 1
  • s

    shahrukh ahmed

    10/24/2022, 3:28 PM
    I have a model like this
    Copy code
    model User {
      id              Int     @id @default(autoincrement())
      uuid            String  @default(cuid())
    }
    
    model Posts{
      user           User       @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
      id             Int        @id @default(autoincrement())
      @@unique([userId, id])
    }
    My question is, how can I filter an post with
    Post id
    and
    user uuid?
    I know about the userId_id method. Would like guidance on how to include
    uuid
    in some instances. .
    Copy code
    where: {
              userId_id: {
                id: parseInt(id),
                userId
              }
            }
    👀 1
    r
    • 2
    • 3
  • j

    Jenn Junod

    10/24/2022, 6:41 PM
    Hello beautiful humans!! 👋 Thank you in advance! I'm currently stuck on getting the next-forms-app to work with the schema.prisma so that the frontend entry will be added to the mysql database. (Heads up, I'm a bit of a newb so I may be missing something incredibly simple) Repo: https://github.com/jennjunod/tweetytag My attempt at asking the direct question and what I've done to try to solve it: ------------- in
    tweetytag/index.js /
    if I run
    node index.js
    whatever I have
    twitterHandle:
    equal to, it inputs into the database.... RN it's (edited)
    async function main() {
    await prisma.twitterHandle.create({
    data: {
    twitterHandle: '@jennjunod',
    },
    })
    const alltwitterHandles = await prisma.twitterHandle.findMany({
    })
    console.dir(alltwitterHandles, { depth: null })
    }
    so of course I don't always want it to be my name, I want it to be whatever what input in the form
    tweetytag/next-forms-app/pages/index.tsx
    let's me enter the twitter name and on line 35 i can see that's cause
    alert(Is this your Twitter handle? ${(form.twitterHandle.value)})
    sooooo I would think if I can get
    tweetytag/index.js /
    to read
    form.twitterHandle.value
    in this code instead of '@jennjunod' it would update the database but idk what I'm missing not being able to get it all to talk to each other
    sync function main() {
    await prisma.twitterHandle.create({
    data: {
    twitterHandle: '~~@jennjunod',~~
    },
    })
    const alltwitterHandles = await prisma.twitterHandle.findMany({
    })
    console.dir(alltwitterHandles, { depth: null })
    }
    I HOPE this all makes sense
    n
    • 2
    • 4
  • a

    Alex Duguay

    10/24/2022, 8:01 PM
    Hey there been trying to follow along with the Prisma, Mongodb and remix tutorial. The field level validation seems to not work, anyone else run into this?
    r
    • 2
    • 4
1...633634635636637Latest