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

    Manish

    06/01/2021, 12:02 PM
    Hi, In the following query:
    Copy code
    const usersWithCount = await prisma.user.findMany({
      select: {
        _count: {
          select: { posts: true },
        },
      },
    })
    Is it possible to get the count of posts based on a filter such as posts where
    status:'published'
    ? Thanks!
    r
    • 2
    • 2
  • m

    Michael

    06/01/2021, 1:21 PM
    Hi everyone! I'm using prisma with type-graphql. I'm looking for guidance on how to extend a generated model created by
    prisma generate
    I'm able to generate models / resolvers using
    npx prisma generate
    and all is working as expected. I've created a custom resolver and added it to the resolvers array in buildSchema:
    Copy code
    @Resolver((of) => Auction)
    export default class AuctionResolver {
      @FieldResolver((returns) => Number, { nullable: true })
      async totalBids(
        @Root() auction: Auction,
        @Ctx() { prisma }: Context
      ): Promise<number> {
        const totalBids = await prisma.bid.aggregate({
          _count: {
            id: true,
          },
          where: {
            auctionId: auction.id,
          },
        });
    
        return totalBids._count.id;
      }
    }
    The field shows up in graphql playground, but it's not in the generated model class; so when using the model types, I'm getting warnings for
    totalBids
    Property 'totalBids' does not exist on type 'Auction'.ts(2339)
    • 1
    • 1
  • r

    RemiO

    06/01/2021, 3:31 PM
    Hello. Quick question: if I want to create a postgres user with readonly rights, does it make sense to create it through the seed.ts or is it better to have let's say a psql call before I run my code?
    r
    • 2
    • 4
  • d

    Dick Fickling

    06/01/2021, 4:01 PM
    I asked about this in mid March, but just want to see if anything's changed: is there a plan to compile the NAPI library for M1 Macs? Or is there a way for me to compile it myself?
    j
    d
    • 3
    • 5
  • j

    jdkdev

    06/01/2021, 4:07 PM
    Hi I am looking at this example here https://github.com/prisma/prisma-examples/tree/latest/javascript/rest-express and wondering if someone has an example where the routes are spread across several files, do you only want to call
    const prisma = new PrismaClient()
    once? and then reference it throughout the api?
    a
    • 2
    • 5
  • t

    Tharshan

    06/01/2021, 5:17 PM
    Copy code
    /home/tharshan/Projects/uservitals/node_modules/@prisma/client/runtime/index.js:34784
              throw new import_engine_core.PrismaClientUnknownRequestError(message, this.prisma._clientVersion);
                    ^
    
    PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: 
    Invalid `prisma.user.findUnique()` invocation:
    
    
      Can't perform request, as the Engine has already been stopped
        at cb (/home/tharshan/Projects/uservitals/node_modules/@prisma/client/runtime/index.js:34784:17)
        at processTicksAndRejections (node:internal/process/task_queues:94:5)
        at async searchContact (/home/tharshan/Projects/uservitals/api/db/seed.js:54:18)
        at async /home/tharshan/Projects/uservitals/api/db/seed.js:840:23 {
      clientVersion: '2.21.2'
    }
    j
    j
    • 3
    • 22
  • t

    Tharshan

    06/01/2021, 5:17 PM
    What does this error mean?
  • v

    Vicky

    06/01/2021, 5:23 PM
    Hello everyone, I am using Prisma with
    nexusjs
    For one date field, I am using type as Prisma db.date, now date in getting saved in correct format in db But I wanted to know to fetch that field do I need to use
    nexusjs
    custom date type? or it's not required?
    d
    • 2
    • 4
  • l

    Logan

    06/01/2021, 9:42 PM
    result = *await* client*.*prisma*.*invites*.groupBy*({
            
    by: ["inviterId"],
            
    _count: {
              
    inviterId: *true*,
            
    },
            
    orderBy: {
              
    _count: {
                
    inviterId: 'desc',
              
    },
              
    where: {
                
    serverId: message*.*guildID,
                
    valid: *true*,
              
    },
            
    },
          
    });
    Hi, I'm not sure if someone could help me. But I'm currently trying to order this by highest to lowest numbers. But im getting an error which im not sure how to get by.
    Copy code
    Type '{ _count: { inviterId: string; }; where: { serverId: string | undefined; valid: true; }; }' is not assignable to type 'Enumerable<invitesOrderByInput> | undefined'.
      Object literal may only specify known properties, and '_count' does not exist in type 'Enumerable<invitesOrderByInput>'
    r
    • 2
    • 22
  • m

    Manish

    06/02/2021, 5:30 AM
    Hi, I have this query:
    Copy code
    const user = await prisma.user.findFirst({
                where: { username: username },
                include: {
                    posts: {
                        include: {
                            likedBy:true,
                        } 
                    },
                }
            })
    I’m getting a user with a specific user name, and I’m also getting the posts for the user. And for each post, I’m getting likedBy (which is a relation). This works perfectly. However, instead of getting the array of likedBy, if I want to get the count of liked by, I do the following:
    Copy code
    const user = await prisma.user.findFirst({
                where: { username: username },
                include: {
                    posts: {
                        include: {
                            _count: {
                                select: {
                                    likedBy:true
                                }
                            }
                        } 
                    },
    
                }
            })
    This query fails with error: PANIC in query-engine. Can you help me with it? Note that I’m able to use
    _count
    on
    likedBy
    if i’m just getting posts.
    r
    • 2
    • 2
  • a

    Arun Kumar

    06/02/2021, 6:24 AM
    I'd like to loop through the model keys and generate a json/JavaScript object for testing purpose. Is it possible to access the model?
    r
    • 2
    • 13
  • p

    Pooja agrawal

    06/02/2021, 7:24 AM
    Hi everyone
    👋 3
  • b

    Bhavesh Goyal

    06/02/2021, 9:26 AM
    Hey folks!
    👋 3
  • n

    Nishant Salhotra

    06/02/2021, 11:21 AM
    hey Prisma team. Can someone please answer a couple questions about Prisma Migrate? 1. How does it handle transactions within migration files? Eg. I have a migration file (generated by prisma migrate) with 10 sql queries. 3 queries are wrapped in a transaction (
    BEGIN
    ...
    COMMIT
    ). What will happen if one of the queries within that transaction fail? 2. What will happen to the queries executed before a failure during the migration. From what I've observed, the queries executed before the failed query aren't rolled back. But just wanted to check what would be the best practices around making sure that each migration is a transaction? 3. When is
    applied_steps_count
    incremented in
    _prisma_migrations
    table?
    t
    • 2
    • 6
  • m

    Mikastark

    06/02/2021, 12:07 PM
    Is it normal prisma fluent api consider non-nullable relations as nullable ?
    r
    • 2
    • 7
  • h

    Hardik G

    06/02/2021, 12:08 PM
    Hi, is there way to know which field is required in response of query in resolver function logic? So i can use projection in mongoose and get only those field.
    r
    • 2
    • 6
  • h

    Hardik G

    06/02/2021, 12:08 PM
  • a

    Ahmar Suhail

    06/02/2021, 12:28 PM
    Hey, when doing including a model with prisma, is there a way to limit the number of records returned? For eg, I want to include posts when fetching a user, but I only want to get the first 3 posts?
    r
    • 2
    • 5
  • r

    RemiO

    06/02/2021, 12:33 PM
    Hello. Did anyone run into issues with the seed: It says running seed from seed.ts, then your database has been seeded, but the seed.ts script is not executed. I'm sure this is something stupid I did somewhere but I can't seem to figure it out. I commented everything inside the script except a console.log to test and it is the same.
    r
    • 2
    • 4
  • u

    Urmo R

    06/02/2021, 12:58 PM
    Copy code
    model Account {
      Id       BigInt    @unique @default(autoincrement()) @db.BigInt
      Email    String    @unique
      Password String
      Roles    Role[]
      RoleIds  BigInt[]  @unique @db.BigInt
    }
    
    model Role {
      Id        BigInt   @unique @default(autoincrement()) @db.BigInt
      Name      String
      Enum      String
      Account   Account? @relation(fields: [Id], references: [RoleIds])
    }
    
    anyone know how to implement RoleIds reference correctly?
    r
    • 2
    • 23
  • s

    Sun Strike

    06/02/2021, 1:05 PM
    Does prisma allow to have multiple files ?
    r
    • 2
    • 2
  • d

    Dev__

    06/02/2021, 2:44 PM
    hello, i have a column in postgres with boolean values. now when I apply a boolean filter with prisma on that column it doesnt work as intended
    Copy code
    draft:
    	typeof draft !== 'undefined'
    	? {
    		equals: draft // either true or false
    	}
    	: undefined
    the value
    draft
    is either a
    true
    or a
    false
    . when the value is
    true
    it filters correctly and only shows me records with draft value set to
    true
    , but with
    false
    it shows me all records including the ones with
    true
    instead of only record with the draft value set to
    false
    . How could I fix this
    d
    o
    s
    • 4
    • 30
  • a

    Alexandr Bordun

    06/02/2021, 3:37 PM
    Hi is there any way to handle serialization/deserialization with Prisma? when sending/receiving a payload via a message-queue - prisma entities are being “serialized”, hence some of the types are being substituted with primitives (for example,
    Decimal
    type ->
    string
    ) what would be a suggestion on how to work with Prisma types in such cases? (so we can’t use the same types on “workers” methods) I saw some
    {X}OutputType
    definitions, but not for the entities directly
    o
    r
    • 3
    • 2
  • n

    Natalia

    06/02/2021, 3:59 PM
    prisma rainbow We are just about to start our Prisma Meetup! Tune in here:

    https://www.youtube.com/watch?v=1bh4HET5-0Y▾

  • j

    jdkdev

    06/02/2021, 4:02 PM
    how do you explicitly declare table name for model in schema.prisma? (wanting it to be plural)
    d
    • 2
    • 3
  • т

    Тоше

    06/02/2021, 4:06 PM
    is there any workaround for prisma to handle dates such as 000-00-00 via custom scalars, having a simple date crush your production env is far from ideal
    m
    • 2
    • 5
  • n

    Nima

    06/02/2021, 5:22 PM
    Is the data platform/cloud.prisma.io having issues right? just stopped working for me recently
  • n

    Nima

    06/02/2021, 5:23 PM
    s
    • 2
    • 3
  • j

    Jean Suero

    06/02/2021, 5:58 PM
    Hi, i have a question, Prisma Studio doesn't allow select file?
    r
    • 2
    • 3
  • s

    sorenbs

    06/02/2021, 6:09 PM
    Any wasp users out there who want to help out Githubs CTO? https://twitter.com/jasoncwarner/status/1400151723839135745?s=21
1...437438439...637Latest