Skip to content

Implement async query functionality (MySQL and PostgreSQL)#7227

Open
nacholibre wants to merge 2 commits into
doctrine:4.5.xfrom
nacholibre:async_query
Open

Implement async query functionality (MySQL and PostgreSQL)#7227
nacholibre wants to merge 2 commits into
doctrine:4.5.xfrom
nacholibre:async_query

Conversation

@nacholibre
Copy link
Copy Markdown

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
Copy Markdown
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
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions Bot added the Stale label Feb 28, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 7, 2026

This pull request was closed due to inactivity.

@github-actions github-actions Bot closed this Mar 7, 2026
@derrabus derrabus reopened this Mar 19, 2026
Comment on lines +98 to +100
if (! $driverConnection instanceof AsyncConnection) {
throw AsyncNotSupported::driverNotSupported(get_class($driverConnection));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because it completely ignores our middleware architecture.

@derrabus
Copy link
Copy Markdown
Member

Hello @nacholibre. I haven't heard from you since you've opend the PR. Do you want to continue working on this feature?

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