🐉 Fast & standalone PHP MySQL Query Builder library.
Fixed a few more type hints.
A small quality of live release. I've added a lot of missing type hints and fixed wrong ones. This has been long overdue but should now ease working with and IDE.
whereNotIn
helper, thanks @AeonFr : $people->select()->whereNotIn('city', ['Zürich', 'Bern', 'Basel'])->get();
This release fixes an error when trying to pass multiple expression to an order by statement:
$h->table('people')->select()
->orderBy([new Expression('rand()'), new Expression('rand()')])
->execute();
select * from `people` order by func1() asc, func2() asc
There is currently no way changing the direction per order statement in the array syntax. So the direction is set for all given order statements in the array.
$h->table('people')->select()
->orderBy([new Expression('func1()'), new Expression('func2()')], 'desc')
->execute();
select * from `people` order by func1() desc, func2() desc
The fix should also allow mixed arrays:
$h->table('people')->select()
->orderBy(['name' => 'asc', new Expression('func()')], 'desc')
->execute();
select * from `people` order by `name` asc, func() desc
This release brings support for replace queries.
Example:
$h->table('movie_title')->replace([
'movie_id' => '1',
'language' => 'de',
'title' => 'Der Fluch der Karibik'
])->execute();
results in the following query string:
replace into `movie_title` (`language`, `movie_id`, `title`) values (?, ?, ?)
Fixed custom select query object inheritance.
The Select
class is now able to fully inherit its properties from a parent select class.
Example:
class BurgerQuery extends ClanCats\Hydrahon\Query\Sql\Select
{
public function onlyTastyOnes()
{
$this->where('tasty', 1);
}
}
$query = new BurgerQuery(
$h->table('burgers')->select()->limit(50)
);
$query->onlyTastyOnes();
$tastyBurgers = $query->get();
Query flags allow you to store parameters inside a query object. This can be very useful when passing a query object through multiple modifiers.
$movies = $h->table('movies');
$movies->join('review', 'review.movie_id', '=', 'review.id');
$movies->setFlag('reviewIsJoined', true);
// somewhere later ...
if ($movies->getFlag('reviewIsJoined', false)) {
$movies->orderBy('review.rating');
}
1.1.7 is a really small release and changes the following:
vendor/bin/phpunit
.table
method to make the life of IDE users better. Thanks @kingmaryjonatan.This releases does not add any new features but makes the implementation a bit easier.
FetchableInterface
This makes it easy for you to identify if a query should be fetched or not.Example from the readme has been updated:
$connection = new PDO('mysql:host=localhost;dbname=my_database', 'username', 'password');
$hydrahon = new \ClanCats\Hydrahon\Builder('mysql', function($query, $queryString, $queryParameters) use($connection)
{
$statement = $connection->prepare($queryString);
$statement->execute($queryParameters);
if ($query instanceof \ClanCats\Hydrahon\Query\Sql\FetchableInterface)
{
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
});
I've added an EXISTS
query object allowing you to do a query like this one:
SELECT EXISTS(select id from showtimes) as hasShows
Like that:
$h->table('showtimes')->select()->exists(); // returns bool true
Obviously that select query can do everything like the normal select.
$h->table('showtimes')
->select()
->where(function($q)
{
$q->where('start', '>', time());
$q->orWhere('end', '<', time() + 3600);
})
->exists();