Closed Raistlfiren closed 8 years ago
It's cool :+1: .
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.
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.
Thanks for proposing @Raistlfiren! Just released v1.9.9 (2c3cf655e04859d0284a79997213616cb5e5282a) with an implementation of your idea without breaking backwards compatibility. 😉
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