prisma-client-go icon indicating copy to clipboard operation
prisma-client-go copied to clipboard

allow updating all fields in upsert without re-declaring

Open steebchen opened this issue 3 years ago • 3 comments

Creating & Updating the same fields is very repetitive. It would be great to be able to simplify this.

_, err := r.DB.User.UpsertOne(
	db.User.Email.Equals("mock"),
).Create(
	db.User.ID.Set("user_1_mock"),
	db.User.Email.Set("mock"),
	db.User.PasswordHash.Set(r.PW.Hash("mock")),
	db.User.Name.Set("john"),
).Update(
	db.User.ID.Set("user_1_mock"),
	db.User.Email.Set("mock"),
	db.User.PasswordHash.Set(r.PW.Hash("mock")),
	db.User.Name.Set("john"),
).Exec(ctx)
if err != nil {
	return err
}

js equivalent:

const data = { id: "user_1_mock", ... }
prisma.user.upsert({
    where: { ... },
    data: data,
    update: data,
})

steebchen avatar May 21 '21 20:05 steebchen

One suggestion: UpdateAll()?

steebchen avatar May 21 '21 20:05 steebchen

Upsert?

matthewmueller avatar Jun 02 '21 11:06 matthewmueller

This is upsert – it's really just about minimising code if you want to update and create/update all fields in both cases.

steebchen avatar Jun 02 '21 12:06 steebchen