Prisma2 - No createMany - Workaround?
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can we reopen this issue for more discussion?
deleteMany
andfindMany
are available, it seems likecreateMany
is an easy-to-include addition.You can do it like so:
Create take in an array of items.