Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insertOrUpdate, insertOrSkip table methods #2205

Open
yurii-zadryhun opened this issue Jun 29, 2023 · 0 comments
Open

insertOrUpdate, insertOrSkip table methods #2205

yurii-zadryhun opened this issue Jun 29, 2023 · 0 comments

Comments

@yurii-zadryhun
Copy link

These methods would be so useful.

  1. 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

  2. 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 INTO instead of INSERT 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant