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

    Eric Martinez

    06/05/2021, 3:18 PM
    Hey guys, another question. Can we write queries like this with Prisma?
    Copy code
    SELECT p.codigo, f.sumaPctPagado, b.id, b2.comentario
       FROM proyecto p
       LEFT JOIN (
       	SELECT sum(porc_hes) as sumaPctPagado, id_pry
       	FROM facturacion
       	GROUP BY id_pry
       ) f
       ON p.codigo = f.id_pry 
       LEFT JOIN (
       	SELECT max(id) as id, id_pry
       	FROM bitacora
       	GROUP BY id_pry
       ) b
       ON p.codigo = b.id_pry
       LEFT JOIN bitacora b2 
       ON b.id = b2.id
    I tried this
    Copy code
    await prisma.proyecto.aggregate({
        _sum: {
          include: {
            facturacion: {
              porc_hes: true
            }
          }
        }
      });
    And it's not possible, it failed immediatly. Should I "modularize" (move them out of the main query) the nested queries? I see that as an alternative but I haven't tried it yet.
    r
    • 2
    • 2
  • d

    David Ilizarov

    06/06/2021, 5:32 AM
    Howdy. Maybe I'm overthinking this... but lets assume we have something like this:
    Copy code
    model User {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
    
      chats Chat[]
    }
    
    model Chat {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
    
      private    Boolean? @default(false)
    
      users User[]
    }
    I want to find the chat that includes specific users, but I don't want it including other users and it MUST include all users in my array - like if you want a chat with users
    [1,2,3]
    (not just
    [1,2]
    and definitely not
    [1,2,3,4]
    )... this is the best I got.
    Copy code
    this.prisma.chat.findFirst({
            where: {
              users: {
                every: {
                  OR: [{id: 1}, {id: 2}, {id: 3}]
                }
              }
            }
          })
    The problem with the above is that it matches chats for users
    [1,2]
    ... Feels like I might be forced to do a
    chat.findMany
    and then post-query processing. In an ideal world I'd be able to do something like include the count of users I want and then If I include a count of 3, that that coupled with the every OR clause should sufficiently find me my channel. Is that possible? Thoughts?
    r
    • 2
    • 4
  • d

    Daniel Esteves

    06/06/2021, 6:07 AM
    Hi guys, i want to know if there is a way to tell that a field can be of two types, an example i have:
    Copy code
    links         Link[]
    but that also can be of type
    Link[]
    or type
    Embed[]
    , is there a way?
    j
    • 2
    • 3
  • r

    Roblox Studio

    06/06/2021, 7:53 AM
    Hi
    👋 1
  • l

    Levi Lawliet

    06/06/2021, 12:14 PM
    How to pass the parameter in the nested query in graphql? how would the resolver for the same look like? Also how the prisma query would be written I a confused. The prisma1 docs somewhat had an answer to this
    j
    • 2
    • 3
  • j

    John

    06/06/2021, 2:26 PM
    Hi, I am trying to count a relation of an entry but get the error that _count is unknown. How can I do this? thx
  • j

    John

    06/06/2021, 2:26 PM
    model Tree {  id    String @id @default(uuid())  name   String  parentId String?  parent  Tree?  @relation("childrens", fields: [parentId], references: [id])  childrens Tree[] @relation("childrens") }
    ✅ 1
  • j

    John

    06/06/2021, 2:26 PM
    await db.tree.findMany({   where: { parentId: undefined },   include: { _count: { select: { childrens: true } } },  })
    ✅ 1
  • j

    John

    06/06/2021, 2:27 PM
    https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#count
    ✅ 1
  • e

    Eric Martinez

    06/06/2021, 2:30 PM
    Did you add
    previewFeatures = ["selectRelationCount"]
    in your schema file?
    ✅ 1
    👍 1
    j
    • 2
    • 2
  • r

    Ruslan Gonzalez

    06/06/2021, 4:32 PM
    Hello there!
  • r

    Ruslan Gonzalez

    06/06/2021, 4:36 PM
    Is it there any way to ignore unknown args in OrderBy?
  • r

    Ruslan Gonzalez

    06/06/2021, 4:37 PM
    r
    • 2
    • 3
  • d

    Dan Shapir

    06/06/2021, 6:29 PM
    DateTime field in UpdateAt and Created at with default(now) is without timezone (Postgres). How can this be fixed?
    r
    • 2
    • 3
  • w

    William Stanley

    06/06/2021, 8:24 PM
    Anyone have an example of connectOrCreate for multiple nested children?
    Copy code
    db.set.create({
      data: {
        ...someData,
        tokens: {
          createMany: {  // <-- need upsert equiv here
            data: [...tokens]
          }
        }
      }
    })
    • 1
    • 1
  • d

    Danil Kolesnikov

    06/07/2021, 1:28 AM
    Please help understand the usage of
    some
    and
    every
    with a more complex use-case for filtering on relations. Is this a bug with Prisma or I am not using it correctly? Goal: Given an organization id, provide all forms associated with it. Reality: when using
    every
    clause the filtering doesn't work as expected, we get all forms from all organization. When using
    some
    , we get forms from only that organization (expected). Code:
    Copy code
    prisma.applicationFormConfig.findMany({
            where: { organizations: { every: { id: organization.id } } },
    })// yield all forms from all organization
    prisma.applicationFormConfig.findMany({
            where: { organizations: { some: { id: organization.id } } },
          }),// works as expected
    Why? Please help. More context: After inspecting SQL, it becomes obvious why, this is raw query for `every`:
    Copy code
    prisma:query SELECT "public"."ApplicationFormConfig"."id", ... FROM "public"."ApplicationFormConfig" WHERE ("public"."ApplicationFormConfig"."id") 
    NOT IN (SELECT "t0"."A" FROM "public"."_ApplicationFormConfigToOrganization" AS "t0" 
    INNER JOIN "public"."Organization" AS "j0" ON ("j0"."id") = ("t0"."B") 
    WHERE ((NOT "j0"."id" = $1) AND "t0"."A" IS NOT NULL)) OFFSET $2
    look at
    WHERE ((NOT "j0"."id" = $1)
    which will yield all other records.
    $1
    is the
    organization.id
    in the prisma query. When using
    some
    , it is fixed:
    WHERE ("j0"."id" = $1
    Schema:
    Copy code
    model ApplicationFormConfig {
      id            String         @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
    ...
      organizations Organization[]
    }
    
    model Organization {
      id                      String                  @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
    ...
      applicationFormConfigs  ApplicationFormConfig[]
    ...
    }
    r
    • 2
    • 10
  • r

    Ruslan Gonzalez

    06/07/2021, 10:25 AM
    Regarding e2e instead of running separated database connection with same credentials I was wondering if I can make a condition based on the NODE_ENV content for example, in my node's application I have a simple condition to map the development environment like that:
    r
    • 2
    • 13
  • r

    Ruslan Gonzalez

    06/07/2021, 10:25 AM
    ....so is it there any way to make something similar for prisma scheme?
  • u

    user

    06/07/2021, 11:17 AM
    Connect Dev Africa Meetup #1 - Mahmoud Abdelwahab -The Beginner’s Guide to GraphQL

    https://www.youtube.com/watch?v=To7euE2b-zI▾

    In this talk, Mahmoud Abdelwahab introduces the concepts of GraphQL and compares how it differs from REST Mahmoud is a developer advocate at Prisma. He is also a developer, writer, and maker. He is obsessed with and creating exceptional, high-quality content and applications. This talk was recorded during Connect Dev Africa Meetup #1. Join the Meetup Group here: https://www.meetup.com/connect-dev-africa Learn more about Prisma: ◭ Website: https://www.prisma.io​​​ ◭ Docs: https://www.prisma.io/docs​​​ ◭ Quickstart: https://www.prisma.io/docs/getting-started/quickstart-typescript Sent via zapier.com/app/editor/124387382#slack
  • u

    user

    06/07/2021, 11:26 AM
    Connect Dev Africa #1 - Ekene Eze - Building large sites on the Jamstack with On-demand builders

    https://www.youtube.com/watch?v=DnbZhojFtbE▾

    Solving the problem of build times for large Jamstack sites has been challenging to everyone. As a community, we haven’t yet found a one size fits all solution to this problem, as always, there are trade-offs. In this talk, we’ll look at what others have done to solve this problem, what worked, what didn’t, and finally introduce the ODB approach that looks to be a promising solution Ekene is a Developer Experience Engineer at Netlify. When he's not working and doing Jamstack-y things, he likes teaching and learning new things. This talk was recorded during Connect Dev Africa Meetup #1. Join the Meetup Group here: https://www.meetup.com/connect-dev-africa Learn more about Prisma: ◭ Website: https://www.prisma.io​​​ ◭ Docs: https://www.prisma.io/docs​​​ ◭ Quickstart: https://www.prisma.io/docs/getting-started/quickstart-typescript
  • n

    Natalia

    06/07/2021, 4:12 PM
    🎉 All Prisma Day Talks and Workshops are now LIVE: prisma.io/day 🚀 This year, Prisma Day is June 29th and 30th, and features: 💎 11 Prisma workshops in different languages: 🇰🇷🇯🇵🇨🇳🇵🇹🇪🇸🇩🇪🇷🇺🇫🇷🇵🇱🇮🇹uk (sign up on the site) 💎  8 framework workshops, with topics like: GraphQL, Next.JS, Blitz, Redwood, Amplication, Wasp, etc 💎  17 talks: on Jamstack, Prisma, Customer Stories, Connection Management 🦚 Plus: fun swag, special guests, Q&A, prizes to be won! 👋  Hope to see everyone there! <!here>
    🇵🇱 5
    fast parrot 10
    🌏 5
    🦜 9
    🔥 3
    🌎 4
    prisma cool 8
    prisma green 8
    🌍 4
    🚀 4
  • l

    Levi Lawliet

    06/07/2021, 4:12 PM
    Just dropped in to say cloud.prisma.io is simply awsum!!! I have been using prisma for 3 months now! Kudos to the team behind prisma studio!! Only caching is missing, rest is very neat and very useful!
    💚 5
  • j

    juanloco

    06/07/2021, 4:24 PM
    Hi all — is there a way to run a seed command on a prisma/express app already running in heroku? I tried to just do a
    npx prisma db seed --preview-feature
    from the heroku console. The command seemed to run, and then process exited but there is still no data in the DB. I have run this locally and it has worked perfectly fine.
    r
    • 2
    • 18
  • l

    Levi Lawliet

    06/07/2021, 5:02 PM
    Hi, I am trying to search for tags in graphql and need some help with the Prisma
    AND
    operation. I have a schema graphql schema like this
    d
    • 2
    • 32
  • d

    Dan Shapir

    06/07/2021, 5:47 PM
    I keep getting a Drift detected when trying to do
    px prisma migrate dev --name initial-migration --create-only
    but
    npx prisma db push
    returns all is synced. even did and introspect. I don’t have any migrations, I worked only with db push until now.
    d
    l
    j
    • 4
    • 7
  • d

    Dan Shapir

    06/07/2021, 5:59 PM
    I just want to start using the migrations 😞 But it requires to reset the DB which I can not do (and prefer to validate now that it won’t happen in production as well)
  • g

    Giorgio Delgado

    06/07/2021, 6:32 PM
    Say I have a
    ON DELETE CASCADE
    trigger set up on my foreign key reference … where can I see that in
    mysql
    ? I tried looking inside the
    information_schema.triggers
    table and didn’t find anything 😕
  • g

    Giorgio Delgado

    06/07/2021, 6:34 PM
    Or I guess just generally, how could I list all fo the
    ON DELETE
    or
    ON UPDATE
    triggers that I have on my database?
  • g

    Giorgio Delgado

    06/07/2021, 6:34 PM
    … again, specifically for
    mysql
  • g

    Giorgio Delgado

    06/07/2021, 6:39 PM
    turns out that these “triggers” are actually called Referential Actions
1...439440441...637Latest