Perform a Lazy Query



Lazy query

/** @var Lazy<array<Employee>> $employeesLazy */
$employeesLazy = $session
    ->query(Employee::class)
    ->whereEquals("FirstName", "Robert")
    ->lazily();

/** @var array<Employee> $employees */
$employees = $employeesLazy->getValue(); // query will be executed here

Lazy count query

/** @var Lazy<int> $countLazy */
$countLazy = $session
    ->query(Employee::class)
    ->whereEquals("FirstName", "Robert")
    ->countLazily();

/** @var int $count */
$count = $countLazy->getValue(); // query will be executed here

Lazy suggestions query

/** @var Lazy<array<string, SuggestionResult>> $suggestLazy */
$suggestLazy = $session
    ->query(Employee::class, Query::index("Employees_ByFullName"))
    ->suggestUsing(function($builder) { $builder->byField("FullName", "johne"); })
    ->executeLazy();

/** @var array<string, SuggestionResult> $suggest */
$suggest = $suggestLazy->getValue(); // query will be executed here

/** @var array<string> $suggestions */
$suggestions = $suggest["FullName"]->getSuggestions();

Lazy aggregation

/** @var Lazy<array<string, FacetResult>> $facetsLazy */
$facetsLazy = $session
    ->query(Camera::class, Query::index("Camera/Costs"))
    ->aggregateUsing("facets/CameraFacets")
    ->executeLazy();

/** @var array<string, FacetResult> $facets */
$facets = $facetsLazy->getValue(); // query will be executed here

/** @var FacetResult $results */
$results = $facets["manufacturer"];

Syntax

/**
 * Usage
 *   - lazily();
 *   - lazily(Closure $onEval)
 */
function lazily(?Closure $onEval = null): Lazy;
function countLazily(): Lazy;
/**
 * Usage
 *   - executeLazy();
 *   - executeLazy(Closure $onEval)
 */
public function executeLazy(?Closure $onEval = null): Lazy;
Parameters Type Description
$onEval ?Closure An action to perform on the query results when the query is executed
Return Value
Lazy A lazy instance that will evaluate the query only when needed