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

    Sanyam Bansal

    07/27/2022, 6:49 PM
    Postgres - Perform Inner Join without adding the IN Clause in the query cc: @Pieter
    ✅ 1
    d
    p
    j
    • 4
    • 8
  • d

    Dave Edelhart

    07/27/2022, 7:19 PM
    Since migrations may require a different URL, instead of forcing people to constantly url-switch their environment, can you just create an (optiional) “Migration host” property in the database configuration?
    ✅ 1
    a
    • 2
    • 1
  • d

    Dave Edelhart

    07/27/2022, 9:02 PM
    I am getting an “ECONN REFUSED” from your Prisma Data Proxy (52.205.145.236:443) — is there a way I can see why? The data logs don’t have any event for this.
    ✅ 1
    n
    • 2
    • 2
  • b

    Benjamin Willard

    07/27/2022, 9:50 PM
    👋 Hello, team!
  • b

    Benjamin Willard

    07/27/2022, 9:54 PM
    I have a few questions in regards to some data types I have that are critical. Such as
    BINARY
    ,
    VARBINARY
    ,
    TIMESTAMP
    ,
    JSON
    (This is a custom parser using
    json-bigint
    npm package). Then I also have
    nodejs-snowflake
    npm package I also use which is for all of our major identities. Basically right before a record is inserted if it has an auto-increment with SnowflakeId it will perform the new generated ID. How can I make these possible with Prisma?
    ✅ 1
    n
    • 2
    • 2
  • b

    Benjamin Willard

    07/27/2022, 9:55 PM
    I am currently using sequelize and what not but the issue I am having with them is that when I do a simple "update" statement using the ORM logic it does NOT update the database at all. If I were to execute that same query in let's say MySQL Workbench it works just fine
  • b

    Benjamin Willard

    07/27/2022, 9:56 PM
    I am having to use pure update query calls
  • d

    Dave Edelhart

    07/27/2022, 10:18 PM
    question — is there a way to do an equivalent of “having”? as in - I have a class “task” with child “type” (single foreign key).
    Copy code
    model task_type {
      id          String  @id @default(uuid())
      name        String     @unique
      tasks       task[]
      notes       String?
      order       Int         @default(0)
      parent_id   String?
      parent      task_type?  @relation(name: "parent", fields: [parent_id], references: [id])
      child_tasks task_type[] @relation(name: "parent")
      deleted     Boolean     @default(false)
      interval    Int         @default(0)
    }
    
    model task {
      id           String       @id @default(uuid())
      type         task_type    @relation(fields: [task_type_id], references: [id])
      task_type_id String
      task_events  task_event[]
      notes        String?
      data         Json?
      createdAt    DateTime    @default(now())
      last_work_done  DateTime?
      completedAt  DateTime?
      status       String      @default("started")
      parent_task  task?       @relation(name: "parent", fields: [parent_task_id], references: [id])
      parent_task_id String?
      child_tasks  task[]      @relation(name: "parent")
    }
    Some of the types have “interval” (numeric) and I want to find all the tasks whose (task_)type.interval field is zero.
    ✅ 1
    a
    • 2
    • 2
  • j

    Jeremy Cohen Hoffing

    07/27/2022, 10:26 PM
    Hello, I saw this issue from over a year ago and I basically have the same question if its possible to combine connectOrCreate and upsert: https://github.com/prisma/prisma/discussions/6632
    ✅ 1
    n
    • 2
    • 1
  • b

    Boo

    07/28/2022, 1:29 AM
    Is it possible to combine two prisma selections together in one query and
    orderBy
    the combined result? Meaning...
    Copy code
    .findFirst({
     where: {
        id:  1
      }, {
       select: {
         something: {...},
         somethingElse: {...}
        }
      }
    })
    so combining something and somethingElse within here and then
    orderBy
    both of them all in one query, including pagination
    ✅ 1
    d
    • 2
    • 1
  • h

    Hussam Khatib

    07/28/2022, 6:22 AM
    Is there a way I can the type can be inferred as OR while accessing them? I am selecting data based on roles. if role is admin then defaultAdminSelect and if role is student then defaultStudentSelect. It is typed as defaultAdminSelector, when though I am trying to access data as role student
    Copy code
    if (role === Role.admin)
        user = await prisma.user.findUnique({
          where: {
            id,
          },
          select: defaultAdminSelect,
        });
      if (role === Role.student)
        user = await prisma.user.findUnique({
          where: {
            id,
          },
          select: defaultStudentSelect,
        });
    👀 1
    l
    n
    • 3
    • 7
  • f

    Fredrik Lindberg

    07/28/2022, 8:32 AM
    Hello! I have some models where fields are being optional when I expect them to be required. Can anyone help shed some light on what I might be doing wrong? 😄 More info in thread 🧵
    ✅ 1
    n
    • 2
    • 15
  • o

    Omar

    07/28/2022, 11:19 AM
    Hello all, do you think the community is missing an obvious Prisma Generator? Let me know your ideas
    ✅ 1
    m
    n
    • 3
    • 4
  • m

    Mischa

    07/28/2022, 3:19 PM
    more people are trying prisma with serverless and having a rough time because of the cold starts, bundle size, ESM issues, CJS artifacts (like
    __dirname
    ), schema.prisma file bundling, and lack of aurora Data API support. I think kysely is going to eat prisma in the serverless space unless something is done about those issues (prisma data proxy doesn't count)
    ✅ 1
    n
    • 2
    • 2
  • m

    Max Blancarte

    07/28/2022, 5:20 PM
    its possible to remove fields from the return prisma.model.findFirst (like remove password) ?
    ✅ 1
    m
    a
    a
    • 4
    • 9
  • r

    Rutik Wankhade

    07/28/2022, 6:26 PM
    Hey, I am new to Prisma and trying to implement the like feature on posts in my app. I am trying to follow the approach where every post will have likedBy model which will connect to the user who likes it. So how do I write a query to connect id of the user in likedBy every time someone like a post? just like this but query to add the user in likedBy https://prisma.slack.com/archives/CA491RJH0/p1595334595209500?thread_ts=1595333884.208000&cid=CA491RJH0
    ✅ 1
    j
    n
    • 3
    • 18
  • d

    Dave Edelhart

    07/28/2022, 8:48 PM
    Would it be possible to use Prisma in a “backendless” scenario? I.e., to use it to maintain local state in a javascript application?
    ✅ 1
    j
    a
    n
    • 4
    • 8
  • l

    Logan

    07/28/2022, 8:56 PM
    Hey everyone. I'm currently wondering if its possible to get data from more than one table in a single query? We have a teamMember table, and a user table. We want to fetch information on each user in the teamMember table, and get the corresponding data from the user table. Is this possible to do in one query? Or would I have to use two findMany queries?
    Copy code
    const members = await prisma.teamMember.findMany({
    where: {
          teamId,
        },
      });
    
      const membersInfo = [];
    
      members.map(async (e) => {
        const response = await prisma.user.findFirst({
          where: {
            id: e.userId,
          },
        });
        if(response) membersInfo.push(response);
      });
    ✅ 1
    j
    n
    • 3
    • 4
  • m

    Matt D

    07/28/2022, 9:07 PM
    hey all is it possible to have Prisma “cast” an unsupported column type on the client? I’d like to preserve the type of the column for migrations etc as an int4range but still allow Prisma to provide access to this field as a string via the client
    ✅ 1
    👀 1
    a
    • 2
    • 2
  • v

    Vats Patel

    07/29/2022, 8:59 AM
    Copy code
    Hello everyone
    
    Hereby I am stuck at one place 
    
    there is 1 model like below
    
    model Channel {
      user_id       Int
      user          User           @relation("user_channels", fields: [user_id], references: [id])
      provider_id   Int
      provider      User           @relation("provider_channels", fields: [provider_id], references: [id])
      created_at    DateTime       @default(now())
      updated_at    DateTime       @updatedAt
      deleted_at    DateTime?
      conversations Conversation[]
    
      @@id([user_id, provider_id], name: "user_provider_id")
      @@map("channels")
    }
    
    now there is a model named Conversation
    
    Conversation {
     channel_id Int
     channel  @relation(fields: [channel_id], references: [id])
    ...
    }
    
    But I am not getting what to write or define relation here as there is no id in channel id
    
    have any idea ?
    
    thank you
    ✅ 1
    l
    • 2
    • 4
  • m

    Michael Jay

    07/29/2022, 11:32 AM
    Hey everyone. I have a general data question, and am wondering how best to handle it with Prisma. The use case is centered around sharing. The entities are: • A target asset to be shared • The entity which shares the asset • The entity to which the asset is shared. The target asset could be anything - an image, an office doc, an HTML template (text). The entity which shares the asset is going to be a User or a Group. And the entity to which the asset is shared is also a User or a Group. Each target asset exists in a different DB table, and should be referenced in this Sharing table. For instance, imagine the use case: A User shares an Image with a Group. The image is stored in the Images table, with a UUID ID, and the User and Group are in their respective tables with UUID IDs. If you're still with me, here's where Prisma comes in. I want to create a table called "Shares", and the list of columns I intend to use is: • targetAssetType: string • targetAssetId: UUID (* but could belong to a number of tables - so not a proper FK) • fromEntityType: string • fromEntityId: UUID (same as above) • toEntityType: string • toEntityId: UUID (same as above) As mentioned, the id fields aren't proper foreign keys. I guess there's nothing wrong with just storing UUIDs in them as plain strings and then referencing the related entity by the associated *Type attribute. But I just wonder if Prisma has something slick - or if my plan won't work for some reason. Thanks for any help/feedback/suggestions.
    ✅ 1
    a
    • 2
    • 2
  • l

    Lloyd Richards

    07/29/2022, 12:09 PM
    hey, quick question about running Prisma in Serverless functions: I have an IoT pipeline that currently feeds events and states through a Cloud Function based on PubSub publications. Each function spins up Prisma to read and write data coming down the pipeline. However, sometimes I get a huge amount of data all at once and then i've noticed data getting lost due to an uncaught error:
    Copy code
    Error 429: Quota exceeded for quota metric 'Queries' and limit 'Queries per minute per user' of service '<http://sqladmin.googleapis.com|sqladmin.googleapis.com>' for consumer
    I assume this has something do with Prisma connections or maybe just the way that prisma connects into CloudSQL. I've got a work around at the moment that retries the functions after 60sec to sort the bottleneck, but maybe if someone has experience with a Cloud Function > Prisma > CloudSQL stack then they might have run into the same issue?
    👀 1
    a
    • 2
    • 4
  • u

    user

    07/29/2022, 12:10 PM
    Database access on the Edge with Next.js, Vercel &amp; Prisma Data Proxy The Edge enables application deployment across the globe. This article explores what Edge environments are, the challenges that arise when working in Edge environments and how to access databases on the Edge using the Prisma Data Proxy.
    prisma rainbow 1
    💯 1
  • a

    Arpan Bagui

    07/29/2022, 12:19 PM
    can I create a record for a model A and same time update a record in model B in same query if model A has a reference of model B?
    ✅ 1
    m
    n
    • 3
    • 4
  • m

    Michael Jay

    07/29/2022, 12:38 PM
    Using a Prisma enum like a TypeScript enum Am I correct in assuming that I can basically just use the const generated by the Prisma client like a TypeScript enum? I was trying to dynamically generate an enum based on the output located in the Prisma client, but it seems like essentially I'm just remaking the available const, right?
    Copy code
    export const GroupInvitationStatus: {
      Pending: 'Pending',
      Accepted: 'Accepted',
      Declined: 'Declined'
    };
    
    export type GroupInvitationStatus = (typeof GroupInvitationStatus)[keyof typeof GroupInvitationStatus]
    👀 1
    a
    • 2
    • 2
  • m

    Michael Jay

    07/29/2022, 12:40 PM
    Related to the above question - I asked a similar question on SO, and someone said that the Prisma Client is wrong because you can't use the same name for two exports, even though they're different types of export. But it seems to be working just fine, and my TS files even know which one I want based on usage. Is this person just behind the times? https://stackoverflow.com/questions/73166443/is-there-a-way-to-assure-that-every-value-from-a-type-exists-in-an-enum/73166717#73166717
  • a

    Arpan Bagui

    07/29/2022, 3:12 PM
    I am trying prisma transaction for first time I got this error. Can anyone help me please.
    👀 1
    ✅ 1
    s
    m
    n
    • 4
    • 4
  • s

    Stanislas de Roquemaurel Galitzine

    07/29/2022, 3:14 PM
    Hello everyone. I am trying to fix an issue involving SSR, ts and multiple prisma instances. I have read the different Github issues opened, but none of the solutions work in my - edge - case. Here is the code initializing Prisma:
    Copy code
    import { PrismaClient } from '@prisma/client';
    
    export let prisma: PrismaClient;
    
    if (typeof window === 'undefined') {
      if (process.env['NODE_ENV'] === 'production') {
        prisma = new PrismaClient();
      } else {
        /* eslint-disable @typescript-eslint/ban-ts-comment */
        // @ts-ignore
        if (!global.prisma) {
          // @ts-ignore
          global.prisma = new PrismaClient();
        }
        // @ts-ignore
        prisma = global.prisma;
      }
    }
    This works okay bar from the ugly ts-ignores, which I would like to remove. I can fix this by prepending the code above with:
    Copy code
    declare global {
      var prisma: PrismaClient
    }
    But then it clashes with Jest which throws a
    Duplicate declaration "prisma" error
    .
    What would be the correct way of fixing this, without exporting prisma as default ? Why is Jest confused by this? (I am not sure about the error, seems like Jest is unable to infer that this is the same variable).
    ✅ 1
    l
    n
    • 3
    • 4
  • m

    Michael Jay

    07/29/2022, 4:32 PM
    Can someone point me toward docs for what to expect from the return of a $transaction? I tried to drill down, but got stuck on
    type UnwrapTuple<Tuple extends readonly unknown[]>
    I'm happy to debug it for the answer, but I would prefer to have it in front of my eyes before I try to run it.
    ✅ 1
    n
    c
    • 3
    • 5
  • u

    {Pedrolima}

    07/29/2022, 6:44 PM
    Hi everyone, can anyone please tell me why I should use GraphQL Server with prisma when i can just fetch data directly with prisma?
    👀 1
    l
    a
    • 3
    • 2
1...601602603...637Latest