question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma2 - No createMany - Workaround?

See original GitHub issue

I am sadly aware that there is no createMany ability currently with Prisma2 (or Prisma). So, I am wondering if there is a better approach for my situation. Initially, I planned on uploading an array like so (from within GraphQL playground):

mutation{
  createOneProposal(data:{
    email: "fake@gmail.com"
    name: "Ecommerce"
    types:{
      create:{
        model: PURCHASE
        name: "e-commerce"
        cost: 600
        services:{
          create:{
            service: "Responsive web design"
          }
          create:{
            service: "Another service!"
          }
          create:{
            service: "And yet another service!"
          }
          }
        }
      }
  }){
    created_at
    proposal_id
    types{
      type_id
      services{
        service_id
      }
    }
  }
}

As I learned, this is not allowed. You can only have one create function. So, how exactly could I go about this? Stringify the array, and then break it back apart on the Query side when I want to access it? Doesn’t seem like a great solution…

Any ideas would help. I genuinely just assumed createMany was a thing 😉

Given Model:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("MYSQL_URL_PRISMA2")
}

model Post {
  content      String    @default("")
  created_at   DateTime  @default(now())
  post_id      Int       @default(autoincrement()) @id
  published    Boolean   @default(false)
  published_at DateTime?
  title        String    @default("")
  author       User
}

model Profile {
  bio        String?
  profile_id Int     @default(autoincrement()) @id
  user_id    User
}

model Proposal {
  email       String   @unique
  name        String?
  proposal_id Int      @default(autoincrement()) @id
  created_at  DateTime @default(now())
  types       Type[]
}

model Type {
  cost        Int?
  name        String?
  model       Model?    @default(SUBSCRIPTION)
  services    Service[]
  type_id     Int       @default(autoincrement()) @id
  proposal_id Proposal
}

model Service {
  service_id Int     @default(autoincrement()) @id
  service    String?
  type_id    Type
}

model User {
  email    String    @default("") @unique
  name     String    @default("")
  password String    @default("")
  role     Role      @default(USER)
  user_id  Int       @default(autoincrement()) @id
  posts    Post[]
  profiles Profile[]
}

enum Role {
  USER ADMIN
}

enum Model {
  SUBSCRIPTION PURCHASE CUSTOM
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
AnandChowdharycommented, Apr 29, 2020

Can we reopen this issue for more discussion?

deleteMany and findMany are available, it seems like createMany is an easy-to-include addition.

3reactions
pantharshit00commented, Feb 27, 2020

You can do it like so:

mutation {
  createOneProposal(
    data: {
      email: "fake@gmail.com"
      name: "Ecommerce"
      types: {
        create: {
          model: PURCHASE
          name: "e-commerce"
          cost: 600
          services: {
            create: [
              { service: "Responsive web design" }
              { service: "Another service!" }
              { service: "And yet another service!" }
            ]
          }
        }
      }
    }
  ) {
    created_at
    proposal_id
    types {
      type_id
      services {
        service_id
      }
    }
  }
}

Create take in an array of items.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "createMany does not exists..." in prisma?
I'm using createMany to insert multiple data in just a query (see code below). But the problem is, it does not recognize createMany...
Read more >
CRUD (Reference) - Prisma
This page describes how to perform CRUD operations with your generated Prisma Client API. CRUD is an acronym that stands for: Create; Read;...
Read more >
Prisma ORM Tutorial for Beginners - YouTube
Your browser can't play this video. Learn more. Switch camera ... Prisma ORM Tutorial for Beginners | CRUD, CreateMany, Associations.
Read more >
Bulk Inserting Data with Prisma's createMany Method - YouTube
New at Prisma 2.16 is the createMany method. This method allows developers ... Your browser can't play this video. Learn more. Switch camera....
Read more >
How the F**** does anyone use Prisma in production? - Reddit
If this is a major blocker for you and you can't afford to work around this (e.g. by using a DB driver or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found