question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`upsertMany` Functionality

See original GitHub issue

Problem

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:open
  • Created 2 years ago
  • Reactions:22
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Akxecommented, Nov 25, 2021

@Ezard MySQL supports this too

4reactions
ADanilychevJrcommented, Jul 11, 2022

Would love this as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

createEntityAdapter - Redux Toolkit
A function that generates a set of prebuilt reducers and selectors for performing CRUD operations on a normalized state structure containing ...
Read more >
Type of entities is lost on consecutive upsertMany #1376
Expected behavior: On consecutive upserts via upsertMany type of entities in state should be preserved. See the following flow on https:// ...
Read more >
ngrx EntityAdapter upsertMany with partial updates
I want to upsert this list. For entities that are already present in the store / entity state (matched by id of course),...
Read more >
Entity Adapter - NgRx
The methods are used inside your reducer function to manage the entity collection based ... upsertMany : Add or Update multiple entities in...
Read more >
Angular NgRx Entity - Complete Practical Guide
An in-depth guide to NgRx Entity: learn when to use and why, what problems does it solve, learn its API via a detailed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found