Skip to content

Infering the result type of a Query instance #221

Closed
@arnaud-lb

Description

@arnaud-lb

It may be possible to infer the return type of execute(), getResult(), etc on Query instances when the query string is known statically.

This could be implemented like this:

  • Override the Query and AbstractQuery classes so that they have a type parameter, representing the type of their results (e.g. a Query returning User objects would be a Query<User>)
  • Add a return type extension for EntityManagerInterface::createQuery(), to infer the result type from the query string, and so that we can tel that createQuery() returns a Query<something>

The ResultSetMapper of a Query provides enough info to infer the result type in the most simple cases (e.g. SELECT u FROM User). This would already be super useful. Other cases might require a custom SqlWalker because the ResultSetMapper doesn't provide any information on nullability, for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions