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

    Jaye

    08/19/2021, 9:02 AM
    allo - i have a question about self-joins (joining a model to itself) i have a model
    Workflow
    that looks like this:
    Copy code
    model Workflow {
    id: 
      id                String       @id @default(cuid())
      // ...
      previousReview    Workflow?    @relation("WorkflowToWorkflow", fields: [workflowId], references: [id])
      nextReview        Workflow[]   @relation("WorkflowToWorkflow")
      workflowId        String?
    }
    they can form links in a chain, each one pointing at the next one using the
    workflowId
    column. when i make a query like this:
    Copy code
    const workflow = await prisma.workflow.findUnique({
        where: {
            id
        },
        includes: {
            previousReview: true,
            nextReview: true,
        }
    })
    i can get the previous review fine, but the next review always seems to come out as null, even when it does exist what am i doing wrong?
    r
    • 2
    • 1
  • m

    Mateusz Żmijewski

    08/19/2021, 9:53 AM
    Hey, I have a decimal value in db with a specific precision and scale it's stored in database correctly with all the zeroes at the end, but when I use find query all these zeroes get lost. Is there a way to recover them? I need it for google maps coordinates. Thanks.
    r
    • 2
    • 2
  • m

    Mcd Z

    08/19/2021, 9:58 AM
    Hi, for historical reasons, I still using prisma 1 and some question confusing me. Could I get the related model previous values in ‘$subscribe’? I want to get the old data before some update happen but previousValues only shows scalar type fields. Is my problem possible? How could I watch the complex table which has many relations?
  • u

    user

    08/19/2021, 12:31 PM
    Cloning the Starter Repository

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

    Blog Post: https://www.prisma.io/blog/fullstack-nextjs-graphql-prisma-oklidw1rhw Code: https://github.com/m-abdelwahab/awesome-links 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
  • h

    Halvor

    08/19/2021, 1:17 PM
    Can i use uuid() for primary key? What if a collision occurs? Does prisma detect that and retries?
    r
    d
    • 3
    • 6
  • n

    Naotho Machida

    08/19/2021, 1:44 PM
    How I can get random data from prisma?
    ✅ 1
    r
    o
    • 3
    • 7
  • c

    Cory Da Silva

    08/19/2021, 3:01 PM
    Hi there, I've got a prisma connected to an SQL database locally. Our init migration succeeds in creating the tables and several other migrations run, but we get 1 migration that constantly fails. Even if i delete this migration and add anything new to the schema, every new migration also fails. We've tried everything in the docs to resolve this migration but nothing seems to work. This is the erorr we get:
    Copy code
    Error: P3006
    
    Migration `20210624184346_added_slug_name` failed to apply cleanly to the shadow database. 
    Error code: P3018
    Error:
    A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
    
    Migration name: 20210624184346_added_slug_name
    
    Database error code: 1146
    
    Database error:
    Table 'prisma_migrate_shadow_db_8ffd3d5c-5d54-4052-91f9-c30857576558.applicationconfig' doesn't exist
    
    Please check the query number 1 from the migration file.
    r
    • 2
    • 3
  • d

    dhatGuy

    08/19/2021, 3:44 PM
    Running
    prisma generate
    returns error. Error: Command failed with exit code 3221225781
    r
    • 2
    • 1
  • t

    Tyler Clendenin

    08/19/2021, 8:11 PM
    Question about mocking prisma. It seems that since prisma uses the select argument when typing the return value, I cannot figure out how to mock the return of a sparse object rather than needing every required field of a model
  • k

    Kent C. Dodds

    08/19/2021, 8:17 PM
    What's the easiest way to do a select distinct with a group by? Here's my model:
    Copy code
    model PostRead {
      id        String   @id @default(uuid())
      createdAt DateTime @default(now())
      user      User?    @relation(fields: [userId], references: [id])
      userId    String?
      clientId  String?
      postSlug  String
    }
    I want to be able to get a count of distinct rows by userId and clientId (if the user isn't logged in, then I have a randomly generated ID for their client). I've tried this:
    Copy code
    prisma.postRead.groupBy({
      _count: true,
      by: ['userId', 'clientId'],
    })
    But that returns an array for each group with
    _count
    which I can then add manually, but I'd prefer to do that in the db. I've also tried
    count
    , but I'm not sure what to put in my query... And I looked at aggregate but I can't figure out what I'd put in there either 🤔
    r
    • 2
    • 3
  • i

    inlightmedia

    08/19/2021, 8:47 PM
    Copy code
    BookingToModeratorParticipant (Relation)
    - The id column `id` in link table `_BookingToModeratorParticipant` has been removed.
    It was a Prisma legacy column that is not in use anymore.
    
    
    Applying changes... (0/252)
    Applying changes... (33/252)
    Applying changes... (87/252)
    Applying changes... (102/252)
    Applying changes... (121/252)
    Applying changes... 26.0s
    ���    The Migration failed and has not been performed. This is very likely not a
    ���    transient issue.
    ���    org.postgresql.util.PSQLException: ERROR: column "id" of relation
    ���    "_NotificationParamsToPurchasedService" does not exist
    After migrating from the old datamodel in prisma1@1.30.5 to prisma1@1.34.12 I’m getting this error. I have verified in psql that the ids for all relations are in fact gone. So, the deploy did work the first time (and there were no errors the first time I deployed). So, I’m not sure why prisma now shows this id column removal notice for every relation and then subsequent error stating that it can’t find the id column on one of them. I’m not querying the id column of any relation anywhere explicitly. This happens on every prisma deploy when my app starts now. Any ideas?
    • 1
    • 10
  • k

    kkangsan

    08/19/2021, 9:21 PM
    npm_install_--production_issue.txt
  • k

    kkangsan

    08/19/2021, 9:21 PM
    Can't I get it to work with
    npm install --production
    in docker? I want to lighten the docker image. It would be nice if you could give me an example.
    r
    • 2
    • 3
  • u

    user

    08/20/2021, 7:05 AM
    Setting Up Prisma in Our Project

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

    Blog Post: https://www.prisma.io/blog/fullstack-nextjs-graphql-prisma-oklidw1rhw Code: https://github.com/m-abdelwahab/awesome-links 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
  • l

    lucaslah

    08/20/2021, 7:38 AM
    How do I use the javascript
    Map
    type in the
    schema.prisma
    file?
    r
    • 2
    • 1
  • t

    Tomasz Rojek

    08/20/2021, 7:59 AM
    Hi All I try to run local mongodb 5.0.2 (docker) and prisma but I get message
    This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.
    I add
    retryWrites=false
    but it do not work Any ideas ???
    r
    • 2
    • 2
  • l

    lucaslah

    08/20/2021, 8:03 AM
    Do you get an error when you add
    retryWrites=false
    or dose it just not work?
  • t

    Tomasz Rojek

    08/20/2021, 8:09 AM
    it does not work
  • p

    prgrmmr

    08/20/2021, 8:56 AM
    when it comes to error handling, what's the best practice? This is what my code looks like right now.
    Copy code
    const createUser = (req, res, next) => {
        const { name, email, password } = req.body;
        bcrypt.hash(password, saltRounds, async function(err, hash){           
            if (err) { res.status(400).json(err); }
            try {
                let result = await prisma.user.create({
                    data: {
                        name, 
                        email, 
                        password: hash
                    }
                });
                res.status(200).json(result);
            } catch (e) {
                res.json(e);
            }
        });
    }
    r
    • 2
    • 1
  • n

    Nichita Z

    08/20/2021, 10:27 AM
    Hello! Quick question, when using selectRelationCount to count 1-N relations, why is _count returned as nullable?
  • n

    Nichita Z

    08/20/2021, 10:28 AM
    Talking about the inner | null here, it seems weird.. is there a case in which the post is returned, but the count isn’t for some reason?
    r
    • 2
    • 4
  • f

    fcholak

    08/20/2021, 11:03 AM
    Any course out there to follow for Prisma?
    r
    • 2
    • 4
  • u

    user

    08/20/2021, 12:07 PM
    Prisma Meetup #7 + a raffle! 🎁

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

    ◭ Nick Van Wiggeren (@NickVanWig) - What's new at PlanetScale? Nick Van Wiggeren is a Director of Engineering at PlanetScale, where he runs the teams responsible for the API, front-end, database clients, and much more. Previously, he worked all over the GitHub product, and in many other developer-facing products that you know and (hopefully) love. ◭ Ryan Dsouza (@ryands1701) - Deploying Prisma on Lambda using the CDK In this talk we will learn how Prisma combined with the CDK make deploying and interacting with your database easy on Serverless Ryan is a Developer Success Engineer who loves working with TypeScript and orchestrating applications on the Cloud ◭ Harsh Singh (@HarshhhDev) - Database Design 101 We will go through the basic steps of designing a database, from defining an objective to normalization. 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
  • c

    Chase Roossin

    08/20/2021, 2:12 PM
    Quick question: We are trying to structure a "feed" that could contain information from say two tables (likes and follows). What is the best way to fetch data from both tables sorted in descending order? Everything I am reading online is pointing me to having to create raw UNION queries... was curious if anyone was able to solve this similar problem using just the prisma library? The problem with just two queries and then merging is that they can become out of sync if using pagination, as one table may have more data in it. Thank you!!
    r
    • 2
    • 1
  • n

    Nathaniel Babalola

    08/20/2021, 2:24 PM
    Do I have to use
    connect
    to set a foreignKey....like a userId or I can also just set directly?
    Copy code
    userId: 64
    or
    Copy code
    userId: {
       connect: {
           id: 64
           }
    }
    r
    • 2
    • 2
  • n

    Naotho Machida

    08/20/2021, 4:07 PM
    What prisma doesn't have ORDER BY rand?
  • r

    Robin

    08/20/2021, 5:13 PM
    I am trying to show a leaderboard which shows the user with the most Solves (or the most points through a Solve) in a list. I am trying to do this via an prisma.solve.groupBy(..) but Im not sure how I can include the relations here (challenge.points and user.name). Any hints? This is my schema:
    Copy code
    model Challenge {
      id            Int       @default(autoincrement()) @id
      title      String
      text       String
      solution   String
      points     Int
    
      solves     Solve[]
    }
    
    model Solve {
      user   User @relation(fields: [userId], references: [id])
      userId Int
    
      challenge   Challenge @relation(fields: [challengeId], references: [id])
      challengeId Int
    
      createdAt DateTime @default(now()) @map(name: "created_at")
    
      @@id([userId, challengeId])
    }
  • r

    Robin

    08/20/2021, 5:39 PM
    I managed to do it this way, if someone has a better approach, I'm happy for any hints 🙂
    Copy code
    let users = await prisma.user.findMany({
        select: {
          id: true,
          name: true,
          solves: {
            select: {
              challenge: true,
              createdAt: true,
            },
          },
        },
      });
    
      users = users.map((u) => {
        const sum = u.solves.reduce(
          (previous, current) => previous + current.challenge.points,
          0
        );
        return { ...u, points: sum };
      });
  • i

    inlightmedia

    08/20/2021, 8:36 PM
    Is there a good way to keep the prisma 1.34 service secret from ever becoming an environment variable but still import it into the prisma.yml? Has anyone used any nifty tricks. The prisma 1.34 docs suggest using environment variables to pass the secret to the prisma.yml but that has obvious security concerns. I’d love to know if anyone has anything they’ve done to bypass this security limitation.
  • p

    Piyanggoon Keedmor

    08/20/2021, 9:23 PM
    i try use prisma first time for mongodb but why can’t create 😞
    r
    • 2
    • 1
1...472473474...637Latest