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

    Fabriece Sumuni

    10/27/2021, 8:42 AM
    can
    _count
    be used with
    .findUnique
    ?
    r
    • 2
    • 1
  • k

    Kristofer Pervin

    10/27/2021, 2:04 PM
    Hi there. I was wondering if someone might be able to help me in setting up Helper Methods with Prisma. Is there any way to replicate the following TypeORM class helper function in Prisma? https://gist.github.com/jtushman/673f5cd9c0225ee50951fcf46be24df5
    a
    r
    • 3
    • 5
  • n

    n

    10/27/2021, 3:44 PM
    Hey all how can I update many records where I have the userId + default = true, schema shared in the thread. thanks in advance
    a
    • 2
    • 11
  • e

    Ezequiel Pereira

    10/27/2021, 4:31 PM
    Is there someone I could talk to?
    n
    • 2
    • 2
  • m

    Michael Aubry

    10/27/2021, 5:32 PM
    I am using Prisma in serverless functions and having issues in production
    Column: (not available)
    I think this is due to a concurrency issue? Are there any guides on setting up serverless with AWS RDS?
    r
    • 2
    • 1
  • d

    Danny

    10/27/2021, 5:57 PM
    Anyone with some general SQL knowledge able to help me do a prisma migration to rename a column that already has data? I've created a migration file with
    --create-only
    so I can edit it to copy the data to the new column, but I'm getting an error when trying to execute the file during the actual migration itself
    r
    • 2
    • 7
  • b

    Bruno Casado

    10/27/2021, 6:08 PM
    Hello guys i'm here again asking for help: I need perform the following query:
    Copy code
    select gene_1_id , wi.genotype_emedgene_1, wi.genotype_emedgene_2, genotype_1, genotype_2 from womancare_info wi  
    where 
    	(
    		wi.genotype_emedgene_1 in (select genotype from gene_genotype gg where wi.localization_1 = gg.localization) 
    and
    		wi.genotype_emedgene_2 in (select genotype from gene_genotype gg where wi.localization_2 = gg.localization)
    	) 
    or 
    (
    	wi.genotype_emedgene_1 in (select genotype from gene_genotype gg where wi.localization_1 = gg.localization) and wi.genotype_emedgene_2 = ''
    );
    where:
    Copy code
    wi.genotype_emedgene_1 in (select genotype from gene_genotype gg where wi.localization_1 = gg.localization)
    How do i perform this kind of query using prisma? Filtering by using a parent field on subquery?
  • n

    n

    10/28/2021, 1:52 AM
    out of curiosity does anyway have an example of prisma filtering down, sort, pagination etc in nestjs? thanks in advance
  • d

    David

    10/28/2021, 4:00 AM
    Hey folks, I've not touched my database for a couple of months and I've now made some changes to my prisma schema. When I run
    prisma migrate dev
    I get the "migration was modified after it was applied" for my two most recent ones. No changes have been made to either of the migrations and I'd really like to avoid needing to store and reseed all my current data into prisma. Any ideas why this occurs, what could happen, and how to solve?
    r
    j
    • 3
    • 6
  • t

    terion

    10/28/2021, 8:34 AM
    @Ryan @dpetrick can somebody please address this issue? There is a bug in generated inputs hierarchy and this is somewhat breaking stuff https://github.com/prisma/prisma/issues/9989
    d
    a
    • 3
    • 5
  • d

    Dia TM

    10/28/2021, 10:12 AM
    Will the pictures belong to the user? Or does everything belong to the user?
    generator client {
     
    provider = "prisma-client-js"
    }
    datasource db {
     
    provider = "mysql"
     
    url      = env("DATABASE_URL")
    }
    model User {
     
    id         Int       @id @default(autoincrement())
     
    email      String    @unique @db.VarChar(255)
     
    firstname  String    @db.VarChar(255)
     
    lastname   String    @db.VarChar(255)
     
    created_at DateTime  @default(now())
     
    updated_at DateTime?
     
    posts      Post[]
     
    @@map("users")
    }
    model Post {
     
    id         Int       @id @default(autoincrement())
     
    title      String    @db.VarChar(255)
     
    content    String    @db.Text
     
    images     Image[]
     
    comments   Comment[]
     
    created_at DateTime  @default(now())
     
    updated_at DateTime?
     
    user       User      @relation(fields: [userId], references: [id])
     
    userId     Int
     
    @@map("posts")
    }
    model Image {
     
    id     Int    @id @default(autoincrement())
     
    puth   String @db.VarChar(255)
     
    Post   Post   @relation(fields: [postId], references: [id])
     
    postId Int
     
    @@map("images")
    }
    model Comment {
     
    id      Int    @id @default(autoincrement())
     
    comment String @db.Text
     
    post    Post   @relation(fields: [postId], references: [id])
     
    postId  Int
     
    @@map("comments")
    }
    import { Injectable } from '@nestjs/common';
    import { PrismaService } from '../prisma.service';
    import { Post, Prisma } from '@prisma/client';
    @Injectable()
    export class PostsService {
     
    constructor(private prisma: PrismaService) {}
     
    async findAll(): Promise<Post[]> {
       
    return this.prisma.post.findMany({
         
    include: {
           
    user: {
             
    select: {
               
    firstname: true,
               
    lastname: true,
             
    },
           
    },
           
    images: {
             
    select: {
               
    id: true,
               
    puth: true,
             
    },
           
    },
           
    _count: {
             
    select: {
               
    comments: true
             
    }
           
    },
         
    },
       
    });
     
    }
    }
    r
    • 2
    • 11
  • j

    J Giri

    10/28/2021, 12:14 PM
    Prisma Docs page error
    n
    • 2
    • 3
  • t

    Tyler Clendenin

    10/28/2021, 2:16 PM
    what is the format for setting a default date in prisma manually, ex.
    @default("0001-01-01T00:00:00Z")
    seems to work, but it also seems to always try and change the default in the database with any new migration
    ALTER COLUMN "dateAt" SET DEFAULT '0001-01-01 00:00:00 +00:00'
    .
    @default("0001-01-01 00:00:00 +00:00")
    gives this error
    Copy code
    Error parsing attribute "@default": Expected a datetime value, but failed while parsing ""0001-01-01 00:00:00 +00:00"": input contains invalid characters.
    if i keep creating migrations it keeps trying to alter the columns default
    j
    • 2
    • 2
  • v

    Vladi Stevanovic

    10/28/2021, 2:19 PM
    🗣️ If you missed the Next.js Conference, check out the recordings here: ✨ "Next.js and Prisma: Databases in Serverless Made Easy" by Daniel Norman →

    https://youtu.be/cVIeeFEIKSo?t=9090▾

    ✨ "Building a Course Platform in a Weekend" by Mahmoud Abdelwahab →

    https://youtu.be/csic5bg5gHw?t=719▾

    📝 We have in store more amazing talks about all the ways you can build data-rich apps with Prisma and Next.js and the future of databases in Serverless. Stay tuned! 👀
    👍 2
    🦜 1
  • t

    Tom MacWright

    10/28/2021, 6:24 PM
    a big loop of
    .upsert
    calls is a bottleneck in my app, so I'm trying to switch to either
    createMany
    with ignoring duplicates, or
    queryRaw
    . I'm hitting the issues that (1) there's no
    upsertMany
    . (2)
    createMany
    doesn't return the duplicated rows and
    updateMany
    doesn't let you specify multiple
    where
    conditions, and (3)
    queryRaw
    doesn't appear to support arrays-of-arrays as arguments. This is a bit of a bummer. I'm trying to just have some raw SQL in this part of my app because the ORM-unoptimized version is not sufficient, but the queryRaw bit doesn't seem to work either for this usecase.
    a
    • 2
    • 14
  • t

    Tom MacWright

    10/28/2021, 6:34 PM
    Also Prisma's errors for queryRaw are super opaque, all you get is a generic error code and the row that failed? Really tough to figure out whether, for example, you can pass a date value as an argument to queryRaw.
    r
    • 2
    • 3
  • c

    chrisdrackett

    10/28/2021, 7:46 PM
    we’re running prisma on heroku and haven noticed recently that we’re getting the following:
    Error: Cannot find module '.prisma/client'
    . We haven’t updated prisma or changed anything, so we’re a bit confused and I’m curious if anyone else has seen similar
    r
    • 2
    • 2
  • a

    Austin Zentz

    10/28/2021, 7:54 PM
    is it possible you have an import .prisma/client instead of @prisma/client somewhere? VSCode auto-import will do that sometimes
    c
    • 2
    • 1
  • m

    Michael Aubry

    10/28/2021, 8:01 PM
    Copy code
    model Media {
      id               String      @id @default(cuid())
      createdat        DateTime?   @default(now())
      updatedat        DateTime?   @default(now())
      date             DateTime?
      duration         Float?
      loading          Boolean?
      mediaurl         String?
      name             String?
      thumbnails       String?
      trimmed          Boolean?
      type             String?
      uid              String?
      thumbnailSprites String?
      metadata         String?
      owner            UserMedia[]
    }
    I am facing this error. Is there a way to increase the column character count? Specifically the
    id
    unique column. I am a bit confused which column is causing this issue.
  • a

    Austin Zentz

    10/28/2021, 8:02 PM
    what DB are you using?
  • m

    Michael Aubry

    10/28/2021, 8:03 PM
    PostgreSQL AWS RDS
  • m

    Michael Aubry

    10/28/2021, 8:04 PM
  • m

    Michael Aubry

    10/28/2021, 8:11 PM
    Thoughts?
  • m

    Michael Aubry

    10/28/2021, 8:11 PM
    Im realizing the id field is generated by prisma so if it’s throwing an RDS error it wouldnt make sense
  • a

    Austin Zentz

    10/28/2021, 8:13 PM
    yeah it may make sense to use postgres to generate the ID instead of Prisma
  • a

    Austin Zentz

    10/28/2021, 8:14 PM
    you generally have to initiate that in one of your migrations, (but you wouldn't have to if it's an existing database)
  • a

    Austin Zentz

    10/28/2021, 8:14 PM
    I.E. (this is for UUID not CUID)
  • a

    Austin Zentz

    10/28/2021, 8:14 PM
    id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
  • m

    Michael Aubry

    10/28/2021, 8:15 PM
    It’s an existing DB I can edit it using Postico
  • s

    Sunao Suzuki

    10/29/2021, 1:28 AM
    Hi Now I am implementing prisma middleware. What I want to do by using middleware is to execute SET app.currentTenant='xxxxxx' with every SQL execution to realize tenant isolation of Saas. So my middleware is like this:
    Copy code
    this.$use(async (params, next) => {
          if ( xxxxxxx === yyyyyy ) {
            await this.$executeRaw(`SET app.currentTenant='${tenantId}';`);
          }
          return next(params);
        });
    So I want to confirm that in this case the connection of both executeRaw and next is same or not? Or is this any good way to do this?
    r
    j
    • 3
    • 6
1...500501502...637Latest