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

Please support INSERT ~ SELECT query! #19

Closed
o0h opened this issue Sep 26, 2018 · 1 comment
Closed

Please support INSERT ~ SELECT query! #19

o0h opened this issue Sep 26, 2018 · 1 comment

Comments

@o0h
Copy link
Contributor

o0h commented Sep 26, 2018

Can you support INSERT ~ SELECT val1, val2 FROM tmp WHERE NOT EXISTS(*) statement?

You have already support ON DUPLICATE KEY syntax, but it only helps me UNIQUE/PRIMARY keys' duplication.
I think the feature like bellow make this plugin more useful! 😄


api design

// Behavior's api
public function insertOnce(array $values, array $search = null)

usage 1

Specify search conditions.

$data = ['field1' => $val1, 'field2' => $val2];
$search = ['key' = $key];
$this->Table->insertOnce($data, $search);

generates sql statement bellow

INSERT INTO `table` (`field1`, `field2`)
SELECT "{$val1}", "{$val2}" FROM tmp WHERE NOT EXISTS(    
    SELECT * FROM table WHERE `key` = '{$key}'
)

usage 2

Auto set search conditions with inserting data.

$data = ['field1' => $val1, 'field2' => $val2];
$search = ['key' = $key];
$this->Table->insertOnce($data,);

generates sql statement bellow

INSERT INTO `table` (`field1`, `field2`)
SELECT "{$val1}", "{$val2}" FROM tmp WHERE NOT EXISTS(    
    SELECT * FROM table WHERE `field1` = '{$val1}' AND `field2` = '{$val2}'
)
@itosho
Copy link
Owner

itosho commented Nov 3, 2019

thx!

@itosho itosho closed this as completed Nov 3, 2019
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

2 participants