`upsertMany` Functionality
See original GitHub issueProblem
Upserting many records is inefficient. Currently, calling x
upsert statements (e.g. as part of a single transaction) results in x
SELECT statements followed by y
INSERT statements and z
UPDATE statements, where y + z = x
.
Suggested solution
A more efficient flow would be to do a single bulk SELECT statement, followed by a bulk INSERT statement, followed by however many UPDATE statements are required.
e.g. to upsert 100
records, 50
of which already exist in the DB, Prisma will currently run a total of 100
SELECT statements, 50
INSERT statements and 50
UPDATE statements. With the described solution flow, this could be reduced to 1
SELECT statement, 1
INSERT statement and 50
UPDATE statements. This brings the total statement count down from 200
to 52
.
Alternatives
An alternative would be for a developer to do this manually in each project that uses Prisma
Issue Analytics
- State:
- Created 2 years ago
- Reactions:22
- Comments:9 (2 by maintainers)
@Ezard MySQL supports this too
Would love this as well