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

    abdoaligomaa107

    10/10/2022, 3:48 PM
    i have a question , what is the difference between prisma migrate dev and prisma migrage deploy ?
    βœ… 1
    n
    • 2
    • 3
  • b

    Bryon Mapes

    10/10/2022, 4:28 PM
    I'm using .count on a table. A very large table, I have a where condition on a timestamp column that has a lte and gte to just get one day of values. However this query takes forever when called many times. Does it have to check the whole table even though I put the where limiting it to a very small subset? How can i optimize this
    βœ… 1
    a
    • 2
    • 1
  • l

    lawjolla

    10/10/2022, 4:40 PM
    pgbouncer question... I notice that Prisma no longer caches queries on pooled connections (or at least pgbouncer connections). Is that correct behavior and is there any way to bring the cache back?
    πŸ‘€ 1
    n
    • 2
    • 1
  • s

    Sebastian Gug

    10/10/2022, 7:06 PM
    I'm getting hit with
    @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again
    in production -- my process is to run
    npx prisma generate
    before building the project in the pipeline and then have this step in the docker container:
    Copy code
    COPY ./node_modules/@prisma/client ./node_modules/@prisma/client
    Are there extra steps required? it's a bit of an odd one. If I run these two commands:
    Copy code
    RUN ls
    RUN cd ./node_modules/@prisma/client && ls
    right after, the result is:
  • s

    Sebastian Gug

    10/10/2022, 7:08 PM
    so I can confirm that everything gets copied correctly and it's there
    n
    • 2
    • 1
  • s

    Sebastian Gug

    10/10/2022, 7:16 PM
    what would be the suggested way of copying over the generated client when dockerizing an application?
    βœ… 1
    n
    r
    v
    • 4
    • 6
  • c

    Charlie

    10/10/2022, 9:03 PM
    Anyone know how to format the prisma schema file?
    βœ… 1
    n
    • 2
    • 2
  • j

    Justin Wenning

    10/10/2022, 9:30 PM
    Getting this error after an
    npm i
    in my
    postinstall
    script on a t4g micro EC2 instance in my AWS EB environment. I can
    npm i
    off a freshly-cloned repo on my local machine without issue. What am I doing wrong here?
    Copy code
    > app@0.1.0 postinstall
    > prisma migrate deploy
    node:internal/fs/utils:345
    throw err;
    ^
    Error: ENOENT: no such file or directory, open '/var/app/current/node_modules/.bin/prisma_fmt_build_bg.wasm'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at ../../node_modules/.pnpm/@prisma+prisma-fmt-wasm@4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6/node_modules/@prisma/prisma-fmt-wasm/src/prisma_fmt_build.js (/var/app/current/node_modules/.bin/prisma:12337:31)
    at __require (/var/app/current/node_modules/.bin/prisma:14:50)
    at Object.<anonymous> (/var/app/current/node_modules/.bin/prisma:86202:38)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
    errno: -2,
    syscall: 'open',
    code: 'ENOENT',
    path: '/var/app/current/node_modules/.bin/prisma_fmt_build_bg.wasm'
    }
    npm ERR! code 1
    npm ERR! path /var/app/current
    npm ERR! command failed
    npm ERR! command sh -c prisma migrate deploy
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/webapp/.npm/_logs/2022-10-10T21_19_49_623Z-debug-0.log
    πŸ‘€ 1
    βœ… 1
    n
    • 2
    • 10
  • a

    Amgelo563

    10/11/2022, 1:34 AM
    How could I include
    create
    data when using
    createMany
    like when I do with
    create()
    ? I want to create (and connect) 1 entry for many entries I'm creating at the same time. My use case is a Ticket service where I want to specify TicketAnswers the user answers when creating the ticket; the answers are connected through a one to many connection with Ticket, so I can't create the ticket first, I need to create the answers. So I'm trying to create them using
    prisma.answers.createMany()
    and specifying
    ticket
    like on
    create
    (
    .create({ data: { answerData, ticket: { create: { ticketData } } } })
    ), but I'm not sure how I would do that. Looking at Prisma's index.d.ts doesn't help much since
    TicketAnswerCreateManyInput
    doesn't seem to have that property. Edit: Using a single
    .create()
    with the specified create property and then using that for createMany as a workaround for now; would still like to know if there's a feature I missed or how I could achieve the same on a "cleaner" way
    βœ… 1
    n
    • 2
    • 3
  • d

    DIlpazir Ahmad

    10/11/2022, 4:22 AM
    How can we do a left JOIN with prisma, let say I want to join photos with user. Can anyone help? I am new to prisma
    βœ… 1
    j
    n
    • 3
    • 8
  • d

    DIlpazir Ahmad

    10/11/2022, 10:55 AM
    I am getting this error in one-to-one relationship. Code snapshot attached in comment. Can anyone help?
    βœ… 1
    j
    n
    • 3
    • 3
  • r

    Ran Rosenmann

    10/11/2022, 3:08 PM
    Hi all. looking to get some support from dev team regarding this: https://github.com/prisma/prisma/issues/15013
    βœ… 1
    r
    • 2
    • 1
  • r

    Ran Rosenmann

    10/11/2022, 3:10 PM
    any idea when it's planed to be worked on? we are currently suffering from the same issue. we can also try and help fixing it given some pointers to the correct location in prisma code.
    βœ… 1
    r
    v
    • 3
    • 2
  • a

    Alex Vilchis

    10/11/2022, 7:30 PM
    Hi there! Is it possible to create records in the underlying tables for many-to-many relations? I need to perform a complex migration and I need to massively create the relations between two tables
    πŸ‘€ 1
    βœ… 1
    n
    v
    • 3
    • 4
  • h

    Husnain Saeed

    10/11/2022, 8:25 PM
    do we have anyway to refer to the attributes of the resource we are quering for inside the where statement of the same query
    Copy code
    like 
    prisma.beds.findMany({
        where: {
           House:{
               RepairRecords:{
                   Equipment: {
                     None: { id: <self'id> }
    }
    }
    }
    } 
                        
    })
    n
    • 2
    • 1
  • a

    Austin

    10/11/2022, 8:26 PM
    Hey @Guillermo David, Could you share your
    schema.prisma
    file?
    v
    • 2
    • 1
  • h

    Husnain Saeed

    10/11/2022, 8:52 PM
    or maybe if some can help in a case like
    Copy code
    where: { 
          House: {
              Records: {
                    some: {
                              <check if latest>
    πŸ‘€ 1
    n
    v
    • 3
    • 2
  • a

    Andres

    10/12/2022, 1:04 AM
    Hi I'm repeating my message since it got no answer so far. I'm having a weird thing/bug with migrations which I couldn't seem to figure out. I have column
    title
    which is a String and I'm migrating it to be of an "enum" type, nullable. So I updated the schema and run the
    migrate dev
    command, but it failed because I had some existing values of
    title
    that didn't match the allowed values of the enum, one of which was the empty string
    ''
    . I edited the migration file to convert all
    ''
    to
    NULL
    but somehow this update statement is not working, it does nothing. If I ran it manually in my DB, it works impeccably. Here's my migration file:
    Copy code
    UPDATE `PersonDetail` SET `title` = 'corporate admin' WHERE `title` = 'admin'; -- <=== UPDATE STATEMENT WORKS
    UPDATE `PersonDetail` SET `title` = 'corporate editor' WHERE `title` = 'editor'; -- <=== UPDATE STATEMENT WORKS
    
    -- THIS UPDATE STATEMENT DOES NOTHING, BUT WHEN RAN MANUALLY IN DB, IT WORKS
    -- tried using TRIM(...) and ' ', '   ' and every suggestion here: <https://stackoverflow.com/questions/8470813/how-do-i-check-if-a-column-is-empty-or-null-in-mysql>
    -- nothing worked so far
    UPDATE `PersonDetail` SET `title` = NULL WHERE `title` = '';
    
    -- AlterTable
    ALTER TABLE `PersonDetail` MODIFY `title` ENUM('private investor', 'geologist', 'engineer', 'fund manager', 'analyst', 'other', 'broker', 'metallurgist', 'esg specialist', 'corporate admin', 'corporate editor') NULL;
    βœ… 1
    j
    n
    • 3
    • 4
  • a

    Arpan Bagui

    10/12/2022, 7:12 AM
    Can I get new record as response when using $queryRaw for Insert?
    πŸ‘€ 1
    βœ… 1
    r
    j
    • 3
    • 34
  • d

    Donald Dewulf

    10/12/2022, 10:57 AM
    qq (I hope), how can I define an Unsigned Decimal in a prisma schema? (mysql)
    βœ… 1
    j
    n
    v
    • 4
    • 12
  • e

    Evangelos Charalampidis

    10/12/2022, 3:57 PM
    await prisma.comment.update({
    where: {
    id: id,
    },
    data: {
    likes: likes,
    },
    });
    does the update call alter both the updatedAt and the createdAt entries? It should not, right? @Nurul
    βœ… 1
    n
    • 2
    • 2
  • h

    Hassan Anwar

    10/12/2022, 4:10 PM
    Hi there, I'm working on golang with prisma mysql I got stuck in Updating the data. Here's the code I'm working with:
    Copy code
    update, err1 := h.client.Projects.FindUnique(
                db.Projects.ProjectGUID.Equals(project.ProjectGUID),
             ).Update(
                 db.Projects.Title.Set(project.Title),
                 db.Projects.Description.Set(project.Description),
             ).Exec(context.Background())
    and My DB:
    Copy code
    model Users {
          Id      Int     @id @default(autoincrement())
              Guid    String  @unique
              Email       String  @unique
              Name        String
              Password    String
              Role        Role    @default(USER)
              SecretKey   String  @default("")
              IsDeleted   Boolean @default(false)
              DateCreated DateTime @default(now())
              Projects    Projects[]
    }
    model Projects{
         Id Int  @id @default(autoincrement())
         ProjectGuid  String  @unique
         UserGuid    String
         Title   String
         Link   String?
         Description String
         Users   Users    @relation(fields:[UserGuid], references:[Guid])
    }
    βœ… 1
    r
    • 2
    • 2
  • h

    Hassan Anwar

    10/12/2022, 4:11 PM
    Can anyone help me with the query
  • h

    Hassan Anwar

    10/12/2022, 4:12 PM
    If it's not possible, Can anyone tell me how can I use prisma mysql raw query in golang
    πŸ‘€ 1
    r
    • 2
    • 1
  • j

    Jakob Clausen

    10/12/2022, 5:06 PM
    Hey! I have a problem when trying to fetch β€œprojects” on my user query. I have added a many-to-many relationships like this.
    Copy code
    model User {
      id        Int               @id @default(autoincrement())
      createdAt DateTime          @default(now()) @map("created_at")
      updatedAt DateTime          @updatedAt @map("updated_at")
      name      String
      email     String            @unique
      projects  UsersInProjects[]
    
      @@map("user")
    }
    
    model Project {
      id        Int               @id @default(autoincrement())
      createdAt DateTime          @default(now()) @map("created_at")
      updatedAt DateTime          @updatedAt @map("updated_at")
      name      String
      customer  String
      users     UsersInProjects[]
    
      @@map("project")
    }
    
    model UsersInProjects {
      id        Int     @default(autoincrement())
      user      User    @relation(fields: [userId], references: [id])
      userId    Int     @map("user_id")
      project   Project @relation(fields: [projectId], references: [id])
      projectId Int     @map("project_id")
    
      @@id([userId, projectId])
      @@map("users_in_projects")
    }
    And my typeDefs types looks like this =>
    Copy code
    type User {
        id: Int!
        createdAt: DateTime!
        updatedAt: DateTime!
        name: String!
        email: String!
        projects: [Project]
      }
      type Project {
        id: Int!
        createdAt: DateTime!
        updatedAt: DateTime!
        name: String!
        customer: String!
        users: [User]
      }
    This is my query =>
    Copy code
    context.prisma.user.findMany({
            skip: args.offset ?? 0,
            take: args.limit ?? 10,
            include: {
              projects: true,
            },
          });
    I get error from this. It says that name does not exit. So it tries to get fields from UsersInProjects. But want to be able to fetch users on projects and vice versa. Any ideas?
    βœ… 1
    n
    • 2
    • 10
  • b

    benjick

    10/12/2022, 5:16 PM
    Hello! Given the following schema:
    Copy code
    model Integration {
      id       String @id @default(auto()) @map("_id") @db.ObjectId
      type     String
      settings Json
    
      owner   User   @relation(fields: [ownerId], references: [id])
      ownerId String @db.ObjectId
    }
    How come I can't run the following?
    Copy code
    prisma.integration.delete({
      where: {
        id: input.id,
        ownerId: ctx.session!.user!.id,
      },
    });
    Giving me this error:
    Object literal may only specify known properties, and 'ownerId' does not exist in type 'IntegrationWhereUniqueInput'.
    βœ… 1
    r
    • 2
    • 6
  • m

    Moonchild Everlasting

    10/12/2022, 5:32 PM
    hi i have a question regarding testing and typescript
    βœ… 1
    r
    • 2
    • 1
  • m

    Moonchild Everlasting

    10/12/2022, 5:33 PM
    where should i write it ?
    βœ… 1
    r
    • 2
    • 2
  • r

    Robert Lee

    10/12/2022, 5:39 PM
    Say I want to implement tags as a scalar list (for simplicity rather than many to many lookup table)
    Copy code
    model Taggable {
      tags   String[]
    }
    How would I go about finding the distinct set of tags in Taggable? Group by seems to be looking at the list as an immutable array rather than considering each element in the tags array:
    Copy code
    const tags = await prisma.taggable.groupBy({
          by: ["tags"],
          _count: {
            tags: true,
          },
          orderBy: {
            _count: {
              tags: "desc",
            },
          },
        });
    Returns something like:
    Copy code
    [
      {
        "_count": {
          "tags": 1
        },
        "tags": ["Tag #1"]
      },
      {
        "_count": {
          "tags": 1
        },
        "tags": [ "Tag #1", "Tag #2"]
      }
    ]
    Where I want something like
    Copy code
    [
      {
        "_count": {
          "tags": 2
        },
        "tag": "Tag #1"
      },
      {
        "_count": {
          "tags": 1
        },
        "tag": "Tag #2"
      }
    ]
    Any ideas?
    βœ… 1
    πŸ‘€ 1
    n
    • 2
    • 1
  • m

    Moonchild Everlasting

    10/12/2022, 5:40 PM
    uppin a github repo
    πŸ‘€ 1
    r
    n
    • 3
    • 6
1...631632633...637Latest