-
Notifications
You must be signed in to change notification settings - Fork 28
Mass inserOrUpdate Elequent and DB #1325
Comments
You are always welcome to submit a pull request. Using a tone like that will certainly not encourage anyone to implement this feature. |
The fact that after so many years this basic feature is missing is frustrating enough. |
Apparently, other users disagree with you on the importance of this feature. |
Which is very disturbing don't you think? |
I don't see why that would be disturbing. Maybe this is just a rare use case and only very few people have ever needed such a feature. |
What you call "insert or update" is often called "upsert" (update or insert) and is a supported in many database engines, albeit with proprietary syntax. The If we were to attempt batch inserts we would could bunch some records together into a single However, once we move into upserts we run into problems on how to write the And then we have yet another problem; insertOrUpdateGetIds is expected to return the identifiers of the records upserted. This basically forces us to execute one How have you solved all these problems in your solution where you only use 3-4 requests per table? |
For MySQL, there is this package: https://github.com/yadakhov/insert-on-duplicate-key |
Thank you for your concern. The creator if the library says
Perhaps I am mistaking but I don't know how is |
In my case ON DUPLICATE KEY
updated_at=IF(
name=VALUES(name) && color=VALUES(color) && ....,
updated_at, VALUES(updated_at)
) and moves with the updated ones and we have $affectedRecords = DB::table('table')
-> select('id')
-> where('updated_at', '=', $updatedAtValue)
-> get();
This isn't a knew problem in general there are ORMs that have solved the problem from a long time. I'm not an expert on ORMs there are many cases and specifics that are taken into consideration but mass upsert is an everyday problem. |
@webbby So you basically know things about your code, you have limitations in your solution that you've accepted. You know that there will be no conflicts, no one else is touching that updated_at column while you're executing your code. A framework cannot make such assumptions. A framework solution needs to work without assuming you're the only writer to the table. A framework cannot assume that you will always have an update_at column either. Have you tried writing sql statements that would work without the update_at column? Because that's what the framework solution have to do. Can you provide us links to other orms that supports these features; batch-upserting and returning the modified identifiers? We can probably look at how they have solved it and build an appropriate Laravel solution. |
@sisve I am aware that my solution is not appropriate. $table->upsertUid(); If I had the option I would gladly use it. |
You mentioned that other orms has solved this problem. Can you tell us about any specific orm? It would be easier to implement this if we knew how others have implemented it. |
I've created an UPSERT package for all databases: https://github.com/staudenmeir/laravel-upsert |
I don't know how to put it guys and I'm sure I am not the first but no convenient multiple records insertion and multiple
insertOrUpdate
in 2018 in a framework that is extremely popular is just unacceptable.Pardon me if I'm missing something but I just don't get it ...
You add some relatively minor features to the framework with each release when the ORM and the DB Builder doesn't support widely used and important features at least not in a convenient way.
I am facing really unpleasant issue where I need to insert or update already related structures of data and there's nothing in the documentation of how to insert or update multiple records in single request and moreover if we add constraints and
many to ...
relationships the situation gets even worse.So in my best scenario I have to make 3-4 requests per table and its constraints if I'm lucky to find enough information of your DB tool and efficient enough SQL queries or if I follow your documentation
thousands
of requestsIs it so hard to have:
What am I talking about perhaps I am asking too much.
At least can we get
Model::insert
with autocreated_at
The text was updated successfully, but these errors were encountered: