IssueRaiser

Provide `upsertMany()`/`upsertFirst()` operation in the client API

## Problem <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] --> I'm frustrated when I want to do an upsert of a specific row, but I don't have fields that are in `<Model>WhereUniqueInput` - I only have fields that, according to my business logic, will find a unique row. Currently, I have to do a findFirst to find the ID of the row, then either a create if it doesn't exist or an update if it does. ## Suggested solution <!-- A clear and concise description of what you want to happen. --> Add a CRUD query `upsertMany`. If the where clause finds at least one row, then an update is performed, else, a create is performed. ```ts export type UserUpsertManyArgs = { select?: UserSelect | null include?: UserInclude | null where?: UserWhereInput | null create: UserCreateInput update: UserUpdateInput } ``` I'm not sure what it should return, some possibilities are: * the number of updated objects (probably 0 if a create is done); in which case don't have the `select` or `include` parameters * a list of the updated objects, or the object itself if a create is done * the number of updated objects, or the object itself if a create is done

Posted by olliechick on Nov 2, 2020, 10:34 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

github (Other)

Provide `upsertMany()`/`upsertFirst()` operation in the client API

olliechickNov 2, 2020, 10:34 PM

## Problem <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] --> I'm frustrated when I want to do an upsert of a specific row, but I don't have fields that are in `<Model>WhereUniqueInput` - I only have fields that, according to my business logic, will find a unique row. Currently, I have to do a findFirst to find the ID of the row, then either a create if it doesn't exist or an update if it does. ## Suggested solution <!-- A clear and concise description of what you want to happen. --> Add a CRUD query `upsertMany`. If the where clause finds at least one row, then an update is performed, else, a create is performed. ```ts export type UserUpsertManyArgs = { select?: UserSelect | null include?: UserInclude | null where?: UserWhereInput | null create: UserCreateInput update: UserUpdateInput } ``` I'm not sure what it should return, some possibilities are: * the number of updated objects (probably 0 if a create is done); in which case don't have the `select` or `include` parameters * a list of the updated objects, or the object itself if a create is done * the number of updated objects, or the object itself if a create is done

Comments (0)

No comments yet. Start the discussion.

Comment on this issue