ClanCats / Hydrahon

🐉 Fast & standalone PHP MySQL Query Builder library.
https://clancats.io/hydrahon/master/
MIT License
278 stars 58 forks source link

What is the correct way to call arbitrary MySQL functions? #28

Closed NickStallman closed 4 years ago

NickStallman commented 4 years ago

I didn't find any example of how to use arbitrary MySQL functions, it looks like only the provided ones like AVG, MIN and MAX can be used.

I tested sending a Func() object as the right hand side of a where clause and it failed due to param() in the translator checking for expressions but not functions.

It should also be possible to put a function as a SELECT parameter as well. This is useful for converting a datetime to a date for example when querying.

It's possible I missed the method and there just isn't an example highlighting this usage. I did search the code however and only found Func() referenced in the aggregate functions.

mario-deluna commented 4 years ago

This should be possible, can you provide an example that is not working as expected?

I've tried the following:

$h->table('cars')
    ->select([new Func('myCoolFunc', 'a', new Expression('15'))])
    ->execute();

Which resulted in the expected query:

select myCoolFunc(`a`, 15) from `cars`
mario-deluna commented 4 years ago

Closing, let me know if the issue persists.