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

    Ian

    06/24/2021, 10:00 AM
    #AskPrisma I have read the doc where postgres support table inheritance, now I dont know how do we do it in prisma schema??
    r
    • 2
    • 18
  • a

    Ahmar Suhail

    06/24/2021, 10:40 AM
    Hey, we’re moving some of our stack to use AWS Lambda’s and are sometimes seeing this error
    Timed out fetching a new connection from the connection pool
    . I have a couple of q’s around this: • Is this error only thrown when prisma client tries to get a connection from the pool to run a query? Or is also thrown when the DB has reached it’s max connection limit and the prisma client isn’t able to reserve connections to create a connection pool? • If it’s only thrown in the first case, what could be the possible reasons for it to be thrown when all queries are executed sequentially and connection pool size is 5? • We get a prisma client by doing ->
    Copy code
    const getClient = async () => {
    // get connection string stored in AWS parameter store
      return new PrismaClient()
    }
    And then we call
    getClient
    in our handler. So basically anytime a handler is called a new prisma client is initialised. What does this mean in terms of the connection pool? Will prisma create a new pool every time we do
    new PrismaClient()
    ?
    r
    j
    • 3
    • 21
  • d

    Daniell

    06/24/2021, 1:50 PM
    Hey guys, do you know what piece of code is responsible for programatically restarting the typescript server after generating the prisma client?
    r
    • 2
    • 7
  • a

    Ariel Flesler

    06/24/2021, 3:07 PM
    Hey all, do you know if there's a way to specify comments on types/fields to be mapped to database comments? Seems like that doesn't exist but just in case
    d
    • 2
    • 1
  • n

    Nick Fix

    06/24/2021, 5:44 PM
    Hey, I am trying to use the json filtering with nodejs, but it is not giving me back what i expect. I have this json in column
    values
    Copy code
    {
      "test": 10
    }
    and i trying to grab it this way:
    Copy code
    const entries = await this.prismaClient.accountEntity.findMany({
          where: {
            values: {
              path: ["test"],
              gt: 5,
            },
          },
        });
    but it doesn't return anything. I would expect it to return all rows above 5. I have the following preview features:
    previewFeatures = ["orderByRelation", "filterJson"]
    I have tried to upgrade to version 2.25.0 but still no luck. Please let me know if im doing anything wrong
    r
    • 2
    • 5
  • m

    Michael

    06/24/2021, 7:22 PM
    I have a table
    Purchases
    like this:
    Copy code
    id product price date
    1  1       10    2014-01-01
    2  1       20    2014-02-17
    3  1        5    2014-03-28
    4  2       25    2014-01-05
    5  2       12    2014-02-08
    6  2       30    2014-03-12
    And I want to get a result that contains only the record/row that has the max date, by
    product
    . Thus I want to get a result that is like this:
    Copy code
    product price date
    1        5    2014-03-28
    2       30    2014-03-12
    (because above for
    product
    id 1 the most recent date is 2014-03-23 and for
    product
    2 the most recent date is 2014-03-12. Could anyone help me with constructing a query in Prisma to do this (is it even possible?). I assume I'll be issuing a
    groupBy
    ? Thank you.
    j
    • 2
    • 5
  • n

    Nikhil Goyal

    06/25/2021, 8:23 AM
    Is there a way to update Prisma model by adding new rows in the model(database) after a user request?
    r
    • 2
    • 2
  • t

    Traky Richard

    06/25/2021, 8:40 AM
    HELLO PLEASE, how can I make a unit test with Prisma on nestjs project?
    r
    • 2
    • 1
  • s

    Stephen

    06/25/2021, 8:55 AM
    Does anyone know how I can configure certain model fields to be certain types with prisma introspect? I have a MySQL TINYINT(1) being converted to a Boolean when I need it as an Int.
    r
    • 2
    • 6
  • j

    John McElreavey

    06/25/2021, 9:22 AM
    Hey guys, does anyone know if it's possible to easily migrate an Implicit many to many relations table to an explicit many to many relation ?
    r
    t
    • 3
    • 6
  • a

    Alexander Braunreuther

    06/25/2021, 10:04 AM
    Hi there, we’re using prisma migrate to manage our Postgres Schema. The prisma client is used for a part of our architecture - another part accesses the db through other tools. Is there a way to configure triggers through prisma schema? The first thing we have problems with is the updatedAt which only gets updated through the prisma client as it doesn’t use a trigger but a timestamp from the client. If not - is it something on the roadmap?
    r
    j
    • 3
    • 2
  • s

    Simão Cruz

    06/25/2021, 12:20 PM
    Hello! I didn't found solution before so I will ask for help. I'm trying to dockerize my backend app. I'm doing everything right to generate and aplly migrations to database but when I do "npm run start" command to initialize my backend, it's return this error
    Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
    I already made "prisma generate" command successfully in my dockerfile. How I can solve this? Thanks
    r
    • 2
    • 7
  • j

    jasci

    06/25/2021, 3:56 PM
    Hello guys, wanted to ask about cascading deletes: There are 4 ways to handle it with prisma2 as I see: 1. Manually set it up in the db. 2. Use plugin like this: https://paljs.com/plugins/delete/. But it’s slower I suppose. 3. Implement cascading deletes functionality in the resolvers. 4. Also I thought about creating a migration without applying it with
    prisma migrate dev --createOnly
    than manually modify it to set cascading deletes, kind of like the variant #1 but that way I save it and can apply later to any db (test, staging, prod, etc) Can you please suggest what would be the optimal solution ? Thank you.
    j
    • 2
    • 6
  • a

    Ariel Flesler

    06/25/2021, 5:28 PM
    Hey all!, is there a way to generate a
    .graphql
    file out of the schema, similar to what you got from Prisma 1? Also, is it possible (and somewhat recommended) to expose Prisma directly to the frontend (handling permissions and whatnot ofc)?
    r
    • 2
    • 1
  • h

    Halvor

    06/25/2021, 9:26 PM
    Is there a findOrCreate() function in prisma?
  • h

    Halvor

    06/25/2021, 9:26 PM
    How can i add something only if it does not already exist?
    r
    • 2
    • 1
  • c

    Chip Clark

    06/25/2021, 10:54 PM
    error: Invalid
    prisma.person.findUnique()
    invocation
    Copy code
    Invalid `prisma.person.findUnique()` invocation:
    
    {
      where: {
        PKPersonID: {
          PKPersonID: 7
        }
        ~~~~~~~~~~~~~~~
    I have two functions that are nearly identical. One fails with the above error, the other works fine. This works:
    Copy code
    personByID(id: any) {
        const personID = this.prisma.person.findUnique({
          where: {
            PKPersonID: id
          },
          include: defaultIncludeQuery
        })
        return personID;
      }
    This gives an error:
    Copy code
    personWContacts(id: any) {
        const personContacts = this.prisma.person.findUnique({
          where: { PKPersonID: id },
          include: contactsIncludeQuery
        })
        return personContacts;
      }
    I can switch the includes but the error remains with the personWContacts function.
  • c

    Chip Clark

    06/25/2021, 11:01 PM
    To provide more information: The controller has these 2 functions which calls, the above functions in the service
    Copy code
    @Get(`${Route}/:id`)
      byId(@Param('id', ParseIntPipe) PKPersonID: number) {
        return this.personService.person({
          PKPersonID,
        });
      }
    
      @Get(`${Route}/contacts/:id`)
      contacts(@Param('id', ParseIntPipe) PKPersonID: number) {
        return this.personService.personWContacts({
          PKPersonID,
        });
      }
    • 1
    • 1
  • f

    Filippo Sarzana

    06/25/2021, 11:04 PM
    You are calling the service functions passing an object but you expect a single value
    id
    🤔
    ✅ 1
  • f

    Filippo Sarzana

    06/25/2021, 11:05 PM
    No reason to fail a part from
    include
    params
  • c

    Chip Clark

    06/26/2021, 12:07 AM
    Yes... ugh! Took a long time to see this. Thanks!
  • c

    Christian Villamin

    06/26/2021, 12:28 PM
    Hello, do we have a Nexus channel?
    a
    • 2
    • 2
  • h

    Halvor

    06/26/2021, 1:46 PM
    _sum return "null" if no rows is found. How can i make it return 0 instead?
  • b

    Brian mwangi

    06/26/2021, 2:33 PM
    Hi people. How do I separate the models I have. From the docs it seems they are all state within one file and I have 20 tables. Is there a util function to call them as one?
    👍 1
    r
    • 2
    • 1
  • h

    Halvor

    06/26/2021, 3:01 PM
    can i include fields from a relation in a groupBy() query somehow?
    r
    • 2
    • 1
  • h

    Halvor

    06/26/2021, 3:10 PM
    I have a table with a userId and needs to include username residing in the user model.
  • h

    Halvor

    06/26/2021, 3:26 PM
    Is it possible to autofill table name from variable from model in a raw query?
    r
    • 2
    • 2
  • t

    Tom

    06/26/2021, 8:19 PM
    Does somebody know why these tests only fail sometimes if some tests have been executed before them: https://github.com/tom-richter/prisma-jest-example There is a problem with the seeding in the beforeEach function. After all tests have been run I can see that the data from each of the three tests is in the database. However the db should have been cleared before each test. Run the commands in the Readme.md to reproduce the example. The tests are green if run individually but red if run together. This issue remains the same even if I run the tests it in sequential mode with -i.
    r
    • 2
    • 2
  • s

    Satont

    06/26/2021, 10:43 PM
    How to rewrite that query to prisma?
    Copy code
    const qb: QueryBuilder<UserModel> = (orm.em.fork() as any).createQueryBuilder(UserModel, 'user');
    
          const result: Array<{ id: number; username: string; value: number }> = await orm.em
            .fork()
            .getConnection()
            .execute(
              qb
                .select(['user.id', 'user.username'])
                .where({ username: { $nin: ignored } })
                .join('user.tips', 'tips')
                .addSelect('COALESCE(SUM("tips"."inMainCurrencyAmount"), 0) as "value"')
                .offset(offset)
                .limit(limit)
                .groupBy('id')
                .getKnexQuery()
                .orderBy('value', 'desc')
                .toQuery(),
            );
    r
    • 2
    • 1
  • r

    Ramesh

    06/27/2021, 9:09 AM
    Google Cloud
1...449450451...637Latest