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

    Arun Setty Kodavali

    06/20/2022, 12:08 PM
    Hey guys, I'm fairly new to using prisma and am trying to build a nodejs application with the usage of prisma.
    ✅ 1
    p
    n
    • 3
    • 3
  • a

    Arun Setty Kodavali

    06/20/2022, 12:08 PM
    The thing I'm stuck at is even if I do db pull and generate, prisma shows the following
    Copy code
    UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'findMany' of undefined
    If I restart the server I have, it is working fine. How to actually do CRUD operations after generation without restarting the server? Thanks in advance, Cheers!
    n
    • 2
    • 1
  • y

    Yunbo

    06/20/2022, 7:25 PM
    according to documentation, i should run
    npx prisma dev
    to create migration step which i think its procedure step is create migration -> apply migration -> npx prisma generate. what's the procedure difference between
    npx prisma dev
    and
    npm prisma deploy
    ?
    👀 1
    a
    • 2
    • 2
  • m

    Manthan Mallikarjun

    06/20/2022, 9:08 PM
    Hello, quick db question. I'm working on a project where I take a string like this
    Hello world #welcome #message #other
    and store it. Later they should be able to quickly search by the hashtag. However the string is also editable and I can forsee it being edited multiple times in its lifetime. I was initially thinking of having a
    messages
    table and a
    message_tags
    table. However I realize that since the string can be edited and
    #welcome
    can easily become
    #howdy
    , keeping the
    message_tags
    table in sync might be difficult. In this case am I better off just putting a
    tags
    array column on the
    messages
    table and indexing it?
    ✅ 1
    j
    • 2
    • 4
  • r

    Robert Cornacchia

    06/21/2022, 1:26 AM
    Hey all, huge fan of Prisma! Thanks for creating such an awesome product! Been building a product called Debatable, and trying to extend the schema to have multiple Poll fields in a single debate. Is this possible? Thanks in advance for any help!
    Copy code
    model Debate {
      id        Int          @id @default(autoincrement())
      topic     String
      status    DebateStatus @default(UPCOMING)
      createdAt DateTime     @default(now())
      isDaily   Boolean      @default(false)
      start     DateTime?
      end       DateTime?
      author    User         @relation("UserAuthorsDebate", fields: [authorId], references: [id])
      authorId  Int
      posts     Post[]
      upvotedBy User[]       @relation("UserUpvotesDebate", references: [id])
      poll      Poll?
      revisedPoll Poll?     <------------------------------- Want to add this! 
    }
    
    model Poll {
      id       Int          @id @default(autoincrement())
      debate   Debate       @relation(fields: [debateId], references: [id])
      debateId Int          @unique
      options  PollOption[]
    }
    ✅ 1
    a
    • 2
    • 8
  • k

    KIM SEI HOON

    06/21/2022, 2:18 AM
    Hello everyone! I’m using postgres + Hasura v2.7.0 + Prisma2. After creating Enum_Table inside Hasura, Prisma tried to use Enum Value, but Enum Value inside the table seems to be missing. I want to extract the value of the Hasura Enum Table from Prisma and use it as Enum, what should I do? Below is the example Enum Data that I want. Thank you 🙂
    👀 1
    n
    • 2
    • 1
  • b

    Bartosz Borycki

    06/21/2022, 6:26 AM
    Hi everyone! I'm new to Prisma and generally is awesome, but im stuck on one thing... I'm using MySQL and got models like this:
    Copy code
    model User {
      id              String    @id @unique @default(cuid())
      user            String    @unique
      email           String    @unique
      first_name      String?
      last_name       String?
      skills          Skills[]
    ...
    }
    
    model Skills {
      id       String     @id @unique @default(cuid())
      can_play User[]
      type     SkillsList
    }
    When I try to "register user" i want to connect new user with Skills... Here is my code for create user right now:
    Copy code
    const result = await prisma.user.create({
        data: {
          user: user,
          email: email,
          password: password,
          first_name: first_name,
          last_name: last_name,
          skills: {
            connectOrCreate: skills.map((id: string) => ({
              where: { id: id },
            })),
          },
        },
      });
    Skills is passing in string array with ID of skill, but I've got error:
    Copy code
    Unknown arg `where` in data.skills.connect.0.where for type SkillsWhereUniqueInput. Did you mean `id`? Available args:
    type SkillsWhereUniqueInput {
      id?: String
    }
    Anyone can help me with this?
    ✅ 1
    n
    • 2
    • 2
  • b

    Benjamin Cohen Solal

    06/21/2022, 7:13 AM
    👋 Bonjour, Is there a way to provide a database connection configuration by providing separately the hostname, the port, the username, ... instead of all in one URL? Example:
    Copy code
    datasource db {
      provider = "mysql"
      host      = env("DATABASE_HOST")
      port      = env("DATABASE_PORT")
      ...
    }
    Instead of:
    Copy code
    datasource db {
      provider = "mysql"
      url      = env("DATABASE_URL")
      ...
    }
    Thank you
    ✅ 1
    n
    • 2
    • 3
  • d

    Denis

    06/21/2022, 10:12 AM
    Hi, can someone help to understand why "password" field has modifier "?" in this scheme? I don't get why the password has to be optional and why it causes an error(P1012) when I delete "?".
    ✅ 1
    a
    • 2
    • 1
  • m

    Mischa

    06/21/2022, 7:47 PM
    any idea how to integrate prisma metrics with https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/? and middy?
    ✅ 1
    n
    • 2
    • 2
  • u

    ut dev

    06/21/2022, 9:19 PM
    Hi guys, quick question I want to built a fullstack application with an API. Is Nextjs + Prisma fine for that?
    ✅ 1
    h
    n
    • 3
    • 6
  • n

    Nathan Froese

    06/21/2022, 10:01 PM
    Is there any good Postgres Prisma BRIN examples around anyone can recommend? I’m looking to implementing it for time scheduling
    ✅ 1
    h
    n
    • 3
    • 4
  • v

    Vin Yap

    06/22/2022, 2:14 AM
    Hi, I’m using Prisma with PlanetScale, so I’ve added the table relations and indexes but every time I run
    db pull
    and
    prisma generate
    the indexes gone, is this normal?
    👀 1
    h
    n
    • 3
    • 4
  • y

    Yunbo

    06/22/2022, 2:27 AM
    Create 2 entities and connect in postgesql. relations. 1. account can have multiple jobs (
    @relation("accountsTojobs_account_id")
    in schema.prisma ) 2. account has one
    create_job_id
    (
    @relation("accounts_create_job_idTojobs", fields: [create_job_id], references: [id])
    in schema.prisma ) I'm trying to create a job -> an account according to prisma client relation queries documentation, when i create a
    job
    and include
    account
    ( code below ), i shouldn't have to specify
    create_job_id
    in account object since i won't know the id until its creation. but the vs code throws an error saying
    create_job_id
    is required field. Error Message
    Copy code
    Type '{ email: string; }' is not assignable to type 'Without<AccountUncheckedCreateWithoutJobsInput, AccountCreateWithoutJobsInput> & AccountCreateWithoutJobsInput'.
    my gut tells me i'm missing something on schema file. Could anyone take a look at this and give me some feedback? Thanks in advance, schema.prisma
    Copy code
    model Account {
      id                       Int           @id @default(autoincrement())
      email                 String
      create_job_id            Int
      create_account_job       Job           @relation("accounts_create_job_idTojobs", fields: [create_job_id], references: [id])
      jobs                     Job[]         @relation("accountsTojobs_account_id")
    
      @@map("accounts")
    }
    
    model Job {
      id             Int       @id @default(autoincrement())
      title          String?
      status         String    @default("pending")
      account_id     Int?
      account        Account?  @relation("accountsTojobs_account_id", fields: [account_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "jobs_account_id_fkey")
      accounts       Account[] @relation("accounts_create_job_idTojobs")
    
      @@map("jobs")
    }
    code : account create object throws an error unless i add create_job_id which i won't know until parent(job) is created
    Copy code
    prisma.job.create({
          data: {
            title: `Create an account`,
            status: `PENDING`,
            account: {
              create: {
                email: `<mailto:hello@test.com|hello@test.com>`,
                // create_job_id : ??? i shouldn't have to add this line
              },
            },
          },
        });
    h
    • 2
    • 4
  • k

    Keshav Tangri

    06/22/2022, 3:45 AM
    Hi Any update on prisma supporting SQL functions like GROUP_CONCAT, FIND_IN_SET etc?
    ✅ 1
    n
    • 2
    • 5
  • p

    Priyanshi Gupta (YB)

    06/22/2022, 11:18 AM
    Hi, Is there a way to run the test suites of these prisma packages only for specific databases?
    👀 1
    n
    v
    • 3
    • 3
  • t

    Takis Karyadis

    06/22/2022, 1:11 PM
    hello, i saw prisma and it looks very nice to me, i dind't read yet the documentation
    🙌 3
    n
    • 2
    • 1
  • t

    Takis Karyadis

    06/22/2022, 1:11 PM
    we can write with Prisma complicated sql queries also? with joins etc?
    ✅ 1
    n
    • 2
    • 5
  • m

    Moin Akhter

    06/22/2022, 1:38 PM
    Hello everyone i'm using gcp bucket for resumable upload i have created an endpoint on backend whihc will give me a signedUrl. BACKEND CODE:-
    async getSignedUrl(query, res) {
    try {
    res.set('Access-Control-Allow-Origin', '<http://localhost:3000>');
    const [url] = await storage
    .bucket('my-pandume-bucket')
    .file(query.fileName)
    .getSignedUrl({
    action: 'resumable',
    version: 'v4',
    expires: Date.now() + 12 * 60 * 60 * 1000,
    contentType: 'application/octet-stream',
    });
    return res.json({
    url,
    });
    } catch (error) {
    throw new HttpException(
    error.message || error.response || error,
    HttpStatus.BAD_REQUEST,
    );
    }
    }
    Now i want to use signedUrl given by this endpoint on front end for resumable upload.Now inorder to used it as resumable according to documetation we have to hit a post request using this signedUrl that will give us SessionUrl this session url will be used for resumable upload but when i'm hitting post request using signedUrl which i got from backed refer to above code i'm getting this error. FRONT END CODE:-
    const uploadChunk = useCallback(
    (readerEvent) => {
    axios({
    method: "POST",
    url, ===> Reffering signedUrl which we got from backend code .
    })
    .then((res) => {
    console.log(res.data);
    })
    .catch((err) => {
    console.log(err);
    });
    },
    [url]
    );
    Access to XMLHttpRequest at 'https://storage.googleapis.com/blahblahbla...' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Than using gsutils my cors config is this:
    [{"maxAgeSeconds": 3600, "method": ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS"], "origin": ["<http://localhost:3000>"], "responseHeader": ["Content-Type", "Authorization", "x-goog-resumable", "Access-Control-Allow-Origin"]}]
    Than why i'm getting this error any idea please.
  • m

    mans

    06/22/2022, 4:45 PM
    Hi guys, I am making a webshop for a school assignment. However i Can't figure the following: I have a shopping cart model with several CartItems, each CartItem contains a product ID and a quantity. When adding something to the cart i want to check if the cart already contains a CartItem with the product. And if so incease the quantity. and if not make an item. I cant figure out how to do this. How can i refactur this code to make it work?
    Copy code
    const cart = await prisma.cart.update({
            where: {
                id: dbUser.cartId,
            },
            data: {
                Items: {
                    create: {
                        product: {
                            connect: {
                                id: parseInt(body.productId),
                            },
                        },
                        quantity: parseInt(body.quantity) || 1,
                    },
                },
                totalPrice: 12,
            },
        });
    
        res.json(cart);
    });
    Here is a part of my schema
    Copy code
    model User {
      id            Int     @id @default(autoincrement())
      username      String  @unique
      password_hash String
      role          Role    @default(USER)
      orders        Order[]
      cart          Cart    @relation(fields: [cartId], references: [id])
      cartId        Int
    }
    
    model Cart {
      id         Int         @id @default(autoincrement())
      Items      CartItem[]
      totalPrice Float       @default(0)
      User       User[]
    }
    
    model CartItem {
      id        Int     @id @default(autoincrement())
      Order     Order?  @relation(fields: [orderId], references: [id])
      orderId   Int?
      product   Product @relation(fields: [productId], references: [id])
      productId Int     @unique
      Cart      Cart?   @relation(fields: [cartId], references: [id])
      cartId    Int?
      quantity  Int     @default(1)
    }
    s
    • 2
    • 2
  • o

    Olawale Mayor

    06/22/2022, 7:08 PM
    Hello how do you have use prisma in an express router?
    ✅ 1
    a
    • 2
    • 3
  • h

    Hector Grecco

    06/23/2022, 1:35 AM
    Hello, guys! What’s the more convenient approach to use read/write different database connections on prisma?
    ✅ 1
    n
    • 2
    • 1
  • j

    John Smeeth

    06/23/2022, 4:12 AM
    hi all, I've run
    updateMany()
    got this error
    on prisma.updateManyTransaction. Provided List<Json>, expected TransactionUpdateManyMutationInput or TransactionUncheckedUpdateManyInput:
    my code is
    Copy code
    const updatedTxs = await prisma.transaction.updateMany({
            where: {
              id: {
                in: TxIds,
              },
            },
            data: {
              status: 'SUCCESS'
            },
          });
    what wrong with me?
    👀 1
    ✅ 1
    n
    r
    • 3
    • 3
  • t

    Teun

    06/23/2022, 4:38 AM
    Hi! How can I be 100% sure my production environment does not use Prisma Cloud?
    👀 1
    n
    • 2
    • 2
  • s

    sagar lama

    06/23/2022, 4:56 AM
    Hi, I have a schema that looks something like this,
    Copy code
    model Course {
      id Int @id @default(autoincrement())
      // ...
    
      fee Fee[]
      @@map("courses")
    }
    
    model Fee {
      id        Int        @id @default(autoincrement())
      course_id Int
      course    Course     @relation(fields: [course_id], references: [id])
      feeItems  FeeItems[]
      // ...
    
      @@map("fees")
    }
    
    model FeeItems {
      id                    Int   @id @default(autoincrement())
      amount                 Float
      number_of_installment Int
      fee_id                Int
      fee                   Fee   @relation(fields: [fee_id], references: [id])
    
      // ...
    
      @@map("fee_items")
    }
    I'm trying filter course based on the sum of fee items What's the best way to do it?
    s
    • 2
    • 2
  • j

    John Smeeth

    06/23/2022, 5:03 AM
    hi all, i have an array of id
    const ids = ["id1", "id2"]
    So how can i pass it to `prisma.$executeRaw`UPDATE users SET level=1 WHERE id IN (ids)`` ? thank you
    👀 1
    ✅ 1
    n
    s
    • 3
    • 3
  • u

    user

    06/23/2022, 9:00 AM
    👉 Think like a document - structuring data in documents vs tables - Jesse Hall I Prisma Day 2022 --

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

    -- This talk was recorded on #prismaday | June 16th, 2022. Prisma Day is a community-focused hybrid conference on modern application development and databases. Structuring data as normalized is the standard for relational databases. But who wants to be normal?? Let’s de-normalize our data, put it in documents, and get lightning-fast reads in our applications! In this talk, you’ll learn different methods of storing data in a document database like MongoDB. There are tradeoffs between normalization and denormalization. One will give you faster reads but slower writes, and the other will get you slower reads and faster writes. Which is right for you? By the end of this talk, you’ll know! Jesse Hall, aka codeSTACKr, is a full-stack, self-taught developer with a passion to educate others about all things coding-related. His favorite topics are JavaScript, React, CSS, and of course, MongoDB. Connect with Jesse: https://twitter.com/codeSTACKr
    prisma rainbow 1
  • u

    user

    06/23/2022, 9:00 AM
    👉 From table to pixel. The journey of data w React, Next.js, Prisma - Delba de Oliveira I Prisma Day --

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

    -- This talk was recorded on #prismaday | June 16th, 2022. Prisma Day is a community-focused hybrid conference on modern application development and databases. React is changing the way we think about routing, rendering, and fetching in web applications. Features like React Server Components and Suspense can give us more granular control of when and where to fetch and render content for our routes. In this talk, we’ll explore how everything connects; and how React, Next.js, and Prisma makes it easier to manage the journey of your data, from table to pixel, in just one repo. Delba is interested in helping developers build great web applications. She’s a hobbyist videographer and Senior Developer Advocate at Vercel; where she creates educational content by combining her love for video and code. Connect with Delba: https://twitter.com/delba_oliveira
    prisma rainbow 1
  • u

    user

    06/23/2022, 9:00 AM
    👉 Keynote - Søren Bramer Schmidt I Prisma Day 2022 --

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

    -- This talk was recorded on #prismaday | June 16th, 2022. Prisma Day is a community-focused hybrid conference on modern application development and databases. Søren Schmidt is Chief Architect and Co-Founder of Prisma, building the data platform for modern applications. Before founding Prisma, he lead a team-building foundational infrastructure for Trustpilot. Connect with Søren: https://twitter.com/sorenbs
    prisma rainbow 1
  • b

    BG

    06/23/2022, 9:37 AM
    what do you do if you have a 1tomany if the field is not required. For example. 1 user can only have 1 subscription but a subscription can have multiple users. Sub M - user 1 but whenever i want to create a user it nags about the fact the sub needs to be specified
    👀 1
    n
    • 2
    • 1
1...588589590...637Latest