friends-of-reactphp / mysql

Async MySQL database client for ReactPHP.
MIT License
331 stars 66 forks source link

Updated implementation of query named parameters #169

Open Divi opened 1 year ago

Divi commented 1 year ago

Hello!

I saw a previous pull request about the named parameters. Since there is no activity for 3 years now, I took the liberty to make my own implementation and update the unit tests.

It allows:

$connection->query('SELECT * FROM my_table WHERE foo = :param', ['param' => 'bar']);
$connection->query('SELECT * FROM my_table WHERE foo = :param', [':param' => 'bar']);
$connection->query('SELECT * FROM my_table WHERE foo = :param AND param2 = ?', ['param' => 'bar', 'param2Value']);

Of course, all the previous ways of querying still work. I can update the README if needed.

clue commented 1 year ago

@Divi Thanks for looking into this, would love to get this in!

The additional tests are much appreciated, definitely helps to get some certainty with this feature. It looks like some cases aren't covered right now, can you add some additional tests to ensure this works properly when using the same placeholder name multiple times (SELECT * FROM user WHERE name = :name OR email = :name) and also what happens if the placeholder value contains strings that look like placeholders (['name' => 'is :this a placeholder?']).

Divi commented 1 year ago

Just to let you know, I've not forgotten you, I just don't have enough time for now but I keep in mind your request :)