2017 © Pedro Peláez
 

library insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

image

wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  • Monday, January 29, 2018
  • by wwardaww
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 26 Forks
  • 0 Open issues
  • 22 Versions
  • 0 % Grown

The README.md

MySQL Insert On Duplicate Key Update Eloquent Trait

This Trait forked from yadakhov/ insert-on-duplicate-key(v1.2.0), (*1)

Latest Stable Version License, (*2)

Orginal packet status :

Latest Stable Version License Build Status, (*3)

Insert Duplicate Key Update is a quick way to do mass insert., (*4)

It's a trait meant to be used with Laravel's Eloquent ORM., (*5)

Installing

composer require wwardaww/insert-on-duplicate-key, (*6)

Code Example

use Illuminate\Database\Eloquent\Model;
use Wwardaww\InsertOnDuplicateKey;

/**
 * Class User.
 */
class User extends Model
{
    // The function is implemented as a trait.
    use InsertOnDuplicateKey;
}

Multi values insert.

    $users = [
        ['id' => 1, 'email' => 'user1@email.com', 'name' => 'User One'],
        ['id' => 2, 'email' => 'user2@email.com', 'name' => 'User Two'],
        ['id' => 3, 'email' => 'user3@email.com', 'name' => 'User Three'],
    ];

INSERT ON DUPLICATE KEY UPDATE ANOTHER SCHEME

    User::insertOnDuplicateKey($users,null,'anotherScheme');

```sql -- produces this query INSERT INTO anotherScheme.users(id,email,name) VALUES (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three') ON DUPLICATE KEY UPDATE id = VALUES(id), email = VALUES(email), name = VALUES(name), (*7)

#### INSERT ON DUPLICATE KEY UPDATE DEFAULT SCHEME
```php
    User::insertOnDuplicateKey($users,null);

```sql -- produces this query INSERT INTO homestead.users(id,email,name) VALUES (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three') ON DUPLICATE KEY UPDATE id = VALUES(id), email = VALUES(email), name = VALUES(name), (*8)


```php User::insertOnDuplicateKey($users, ['email']);

```sql -- produces this query INSERT INTO users(id,email,name) VALUES (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three') ON DUPLICATE KEY UPDATE email = VALUES(email), (*9)


#### INSERT IGNORE ```php User::insertIgnore($users);

```sql -- produces this query INSERT IGNORE INTO users(id,email,name) VALUES (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three');, (*10)


#### REPLACE INTO ```php User::replace($users);

```sql -- produces this query REPLACE INTO users(id,email,name) VALUES (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three');, (*11)


### created_at and updated_at fields. created_at and updated_at will *not* be updated automatically. To update you can pass the fields in the insert array. ```php ['id' => 1, 'email' => 'user1@email.com', 'name' => 'User One', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]

Run unit tests

./vendor/bin/phpunit

Will this work on Postgresql?

No. On Duplicate Key Update is only available on MySQL. Postgresql 9.4 has a similar feature called UPSERT. Implementing UPSERT is left as an exercise for the reader., (*12)

Isn't this the same as updateOrCreate()?

It is similar but not the same. The updateOrCreate() will only work for one row at a time which doesn't allow bulk insert. InsertOnDuplicateKey will work on many rows., (*13)

The Versions

29/01 2018

dev-master

9999999-dev https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

1.2.6

1.2.6.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

v1.2.5

1.2.5.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

1.2.5

1.2.5.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

v1.2.4

1.2.4.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

v1.2.3

1.2.3.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

v1.2.2

1.2.2.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

29/01 2018

v1.2.1

1.2.1.0 https://github.com/wwardaww/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

27/04 2017

v1.2.0

1.2.0.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

19/01 2017

v1.1.0

1.1.0.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

01/01 2017

v0.1.0

0.1.0.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

01/01 2017

v1.0.0

1.0.0.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

01/01 2017

v0.0.10

0.0.10.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

30/11 2016

v0.0.9

0.0.9.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Development Requires

database eloquent mysql

28/08 2016

v0.0.8

0.0.8.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

18/07 2016

v0.0.7

0.0.7.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

23/06 2016

v0.0.6

0.0.6.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

07/06 2016

0.0.5

0.0.5.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

14/05 2016

v0.0.4

0.0.4.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

13/05 2016

v0.0.3

0.0.3.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

13/05 2016

v0.0.2

0.0.2.0 https://github.com/yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql

13/05 2016

0.0.1

0.0.1.0 https://github.com/yadakhov/on-duplicate-key-update

A trait for MySQL ON DUPLICATE KYE UDPATE.

  Sources   Download

MIT

The Requires

 

The Development Requires

database eloquent mysql