Adding increment and decrement methods#13
Conversation
Updated the readme
|
Thank you very much! The question is whether $db->increment(
'users',
[ 'balance' => 25 ],
[ 'username' => 'Adam' ]
);is considerably shorter and more convenient than $db->exec(
'UPDATE users SET balance = balance + ? WHERE username = ?',
[
25,
'Adam'
]
);which is already supported today. The answer seems to be yes, it is. Not by a large margin, but still. So it would make sense to add it. I’m not sure if we need separate By the way, I also noticed that in the original Node.js package “knex.js”, this is part of a query builder, not a standalone method as it would be here. That should not really matter, although you cannot create complex conditions without a query builder. |
|
Yes I think with the query builder its much easier, maybe in the future we can work on a query builder, I don't think it's that hard with PHP. actually I thought about using a variable to determine the sign, but I felt it's a little bit unreadable and ambiguous that's way I made a private function for that matter. Those two methods might be some unneeded extras, but I found them fun and useful 👍 |
While working with NodeJS I found some super popular package called knex.js using increment and decrement methods and thought about adding them to this great library