aldaflux/pgsql-doctrine-random-function
RANDOM() function in Doctrine DQL queries, ideal for applications requiring random data sampling (e.g., leaderboards, random recommendations, or testing). Fits well in Laravel/Lumen apps using Doctrine ORM (e.g., legacy systems or hybrid PHP stacks).doctrine/dbal + custom DQL queries).QueryBuilder and DQL, enabling ORDER BY RANDOM() or SELECT RANDOM() in subqueries.getSingleScalarResult() may not work as expected).qbbr/pgsql-doctrine-random-function) is unmaintained (0 stars, no commits since 2016). Fork (aldaflux/...) has no activity or tests.RANDOM() in ORDER BY can be inefficient for large datasets (PostgreSQL’s TABLESAMPLE may be better for analytics).DB::select("SELECT * FROM table ORDER BY RANDOM() LIMIT 10")) or a custom accessor.doctrine/extensions for maintained alternatives or PostgreSQL-specific extensions.pg_random() function usage).ORDER BY RANDOM() or similar logic.EntityManager, QueryBuilder).composer require aldaflux/pgsql-doctrine-random-function
config/packages/doctrine.yaml (or equivalent):
doctrine:
orm:
dql:
numeric_functions:
Random: Qbbr\PgsqlDoctrineRandomFunction\DQL\RandomFunction
ORDER BY random() with ORDER BY RANDOM() in DQL.// Before (raw SQL)
$results = DB::select("SELECT * FROM users ORDER BY random() LIMIT 10");
// After (Doctrine DQL)
$results = $entityManager->createQueryBuilder()
->select('u')
->from('App\Entity\User', 'u')
->orderBy('RANDOM()')
->setMaxResults(10)
->getQuery()
->getResult();
pg_random() function (standard in PostgreSQL 9.0+).RANDOM(seed) or seeded randomness (PostgreSQL’s setseed()).composer.json to avoid auto-updates.doctrine.event_listeners.sql_logger).ORDER BY RANDOM() can be expensive for large tables (PostgreSQL may use a sequential scan).TABLESAMPLE for analytics (not supported by this package).| Failure Scenario | Impact | Mitigation |
|---|---|---|
PostgreSQL pg_random() missing |
Query fails | Verify PostgreSQL version and function availability. |
| Doctrine DQL parsing error | Runtime exception | Validate YAML config syntax. |
| Package compatibility issues | Silent failures or incorrect SQL | Test with Doctrine v3.x; check SQL logs. |
| Large dataset performance degradation | Slow responses, timeouts | Optimize queries; use pagination. |
| Fork abandonment | Unmaintained code | Fork internally or switch to alternatives. |
RANDOM(), setseed()).RANDOM() only for small datasets").How can I help you explore Laravel packages today?