prisma-client-go
prisma-client-go copied to clipboard
Allow props for CreateOne
It would be great if CreateOne
could take in props...
like Update
Currently, I need to do:
var uid *string
if uid == nil {
prisma.User.CreateOne(
prisma.User.Name.Set(...),
prisma.User.Email.Set(...),
)
} else {
prisma.User.FindOne(
prisma.User.ID.Equals(uid),
).Update(
prisma.User.Name.Set(...),
prisma.User.Email.Set(...),
)
}
Would like to do:
var uid *string
var props []prisma.UserParams
if uid == nil {
prisma.User.CreateOne(props...)
} else {
prisma.User.FindOne(
prisma.User.ID.Equals(uid),
).Update(props...)
}
I assume your concern is instead of having fixed required parameters in Create instead of a single variadic parameter.
The reason Create has this parameters is that we can enforce required fields. For example, if you add a new required field in your schema, you'd get a compile time error as an argument is missing or mismatching, whereas with a variadic parameter it would compile with a runtime error.
Do you think the tradeoff is not worth it?
By the way, it looks like you're doing something similar to an upsert – UpsertOne is available now.