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

Added the ability to insert an array of ['column' => 'value'] pairs #35

Closed
wants to merge 2 commits into from

Conversation

Raistlfiren
Copy link

Lazy programmer - added a way to do an insert based upon column/value pairs similar to update($pairs). With the insert statement you can now do

$pairs = ['column' => 'value'];

$db->insert([], $pairs)->into('news');

@Raistlfiren Raistlfiren changed the title Added the ability to insert and array similar to Update Added the ability to insert an array of ['column' => 'value'] pairs Apr 14, 2016
@Raistlfiren Raistlfiren changed the title Added the ability to insert an array of ['column' => 'value'] pairs Added the ability to insert an array of ['column' => 'value'] pairs Apr 14, 2016
@Loic-Rameau
Copy link

It's cool 👍 .

But you should do :

$pairs = ['column'=>'value'];
$db->insert($pairs)->into('yeay');

And change the constructor of InsertStatement to either do the actual stuff or call your custom insertFromArray function if the index of the array is not a number.

@Raistlfiren
Copy link
Author

The problem with doing that is breaking backwards compatibility with the project. The constructor of InsertStatement is looking for an array of columns by default, and I am passing it an array of columns => values. I could check the array key to see if it is a string or integer to automatically call a custom function(I think this is a bad idea.) or have a second argument with the constructor that accepts a function name to call. So InsertStatement would be take in as the constructor Database $dbh, array $columns, $functionName = ''. Then $columns would need to be changed to $pairs or something more general then.

@FaaPz
Copy link
Owner

FaaPz commented May 29, 2016

Thanks for proposing @Raistlfiren! Just released v1.9.9 (2c3cf65) with an implementation of your idea without breaking backwards compatibility. 😉

@FaaPz FaaPz closed this May 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants