v2.9.2
π Release v2.9.2
This release introduces Sharding support, QueryBuilder Macros, and Enhanced WHERE Condition Methods - three major features that significantly expand the library's capabilities.
β¨ What's New
ποΈ Sharding Support
Horizontal partitioning across multiple databases with automatic query routing!
- Three sharding strategies: Range, Hash, and Modulo
- Unified connection pool: Reuses existing connections via
useConnections() - Automatic query routing: Routes queries to the correct shard based on shard key
- Fluent API:
$db->shard('table')->shardKey('id')->strategy('range')->useConnections([...])->register()
// Configure sharding
$db->shard('users')
->shardKey('user_id')
->strategy('range')
->ranges([
'shard1' => [0, 1000],
'shard2' => [1001, 2000],
])
->useConnections(['shard1', 'shard2'])
->register();
// Automatic routing - queries go to correct shard
$user = $db->find()
->from('users')
->where('user_id', 500)
->getOne(); // Automatically routed to shard1π Documentation | π Examples
π§ QueryBuilder Macros
Extend QueryBuilder with your own custom methods!
// Register a macro
QueryBuilder::macro('activeUsers', function() {
return $this->where('status', 'active')
->where('deleted_at', null);
});
// Use it anywhere
$activeUsers = $db->find()
->from('users')
->activeUsers()
->get();π Documentation | π Examples
π― Enhanced WHERE Condition Methods
27 new fluent methods for common WHERE patterns - no more helper functions needed!
// Null checks
->whereNull('deleted_at')
->whereNotNull('email')
// Range checks
->whereBetween('age', 18, 65)
->whereNotBetween('score', 0, 50)
// Column comparisons
->whereColumn('updated_at', '>', 'created_at')
// AND/OR variants for all methods
->andWhereNull('deleted_at')
->orWhereBetween('age', 18, 65)π Documentation
π Improvements
- Fluent Interface: All interfaces now return
staticinstead ofselffor better inheritance support - Composer Metadata: Updated description and added 17 new keywords for better discoverability
- Connection Management: Added
PdoDb::getConnection()method to retrieve connections from pool
π Technical Details
- β All tests passing: Comprehensive test coverage with new sharding, macro, and WHERE condition tests
- β PHPStan Level 8: Zero errors across entire codebase
- β PHP-CS-Fixer: All code complies with PSR-12 standards
- β 100% backward compatible: All existing code continues to work unchanged
π¦ Installation
composer require tommyknocker/pdo-database-class:^2.9.2π Resources
Full Changelog: v2.9.1...v2.9.2