Skip to content

v2.9.2

Choose a tag to compare

@tommyknocker tommyknocker released this 06 Nov 03:33
· 314 commits to master since this release

πŸš€ 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 static instead of self for 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