Skip to content

Conversation

@nacholibre
Copy link

Q A
Type feature

Summary

Quite often I find myself needing async queries in doctrine/orm. In order to implement them first dbal needs to have that functionality.

This PR is me prototyping (consider it proof of concept) for async functionality. Just to note I've used some AI tools to help me prototype and understand the codebase.

I don't consider this as finished product, I just want to get some feedback from the maintainers if my approach is in the right direction and general thoughts about the need of such feature.

The API is as follows:

// Create queries using QueryBuilder
$qb1 = $conn->createQueryBuilder()
    ->select('*')
    ->from('users')
    ->where('status = :status')
    ->setParameter('status', 'active');

$qb2 = $conn->createQueryBuilder()
    ->select('COUNT(*)')
    ->from('orders')
    ->where('created_at > :date')
    ->setParameter('date', '2024-01-01');

// Execute in parallel using the helper method
$results = $conn->executeQueriesAsync([
    AsyncQuery::fromQueryBuilder($qb1),
    AsyncQuery::fromQueryBuilder($qb2),
]);

$users = $results[0]->fetchAllAssociative();
$orderCount = $results[1]->fetchOne();

It works without the QueryBuilder as well

// Execute multiple slow queries in parallel
$results = $connection->executeQueriesAsync([
    new AsyncQuery('SELECT * FROM users WHERE status = $1', ['active']),
    new AsyncQuery('SELECT COUNT(*) as total FROM orders'),
    new AsyncQuery('SELECT AVG(price) as avg_price FROM products WHERE category_id = $1', [5]),
]);

Thanks for your time.

@derrabus
Copy link
Member

Hello and thank you for your pull request. I haven't found the time to review it yet, just one thing: We don't accept new features on the 3.10.x branch anymore. You will need to target our next feature release which currently is 4.5.x.

@derrabus derrabus changed the base branch from 3.10.x to 4.5.x November 29, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants