insertOrUpdate, insertOrSkip table methods
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 4.5k
- Forks
- 884
- PR merge metrics
- No merged PRs in 30d
Description
These methods would be so useful.
-
insertOrUpdate( $insertion, $update ): Inserts a record with the $insertion values or, if it exists, updates the record with the $update values.
Please have a look at Laravel's Eloquent implementation of the updateOrInsert method.
I bet it does something like this
INSERT INTO {$this->table_name} ( user_id, points ) VALUES( %d, %d ) ON DUPLICATE KEY UPDATE points = points + %d -
insertOrSkip( $insertion ): Inserts a record with the $insertion values only if the item doesn't exist. Simple insert() throws the MySQL error (duplicate entry). The implementation is simple:
INSERT IGNORE INTOinstead ofINSERT INTO
Maybe you would also add this method
3. forceInsert( $insertion ): Inserts a record after deleting it if it already exists.
https://dev.mysql.com/doc/refman/8.0/en/replace.html
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by locating the existing table insert() methods, then review Laravel Eloquent's updateOrInsert reference and the linked MySQL semantics for ON DUPLICATE KEY UPDATE, INSERT IGNORE, and REPLACE. Done means the requested methods have defined behavior and coverage for their duplicate-record cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100