groq-builder
Version:
A **schema-aware**, strongly-typed GROQ query builder. It enables you to build GROQ queries using **auto-completion**, **type-checking**, and **runtime validation**.
23 lines (22 loc) • 1.23 kB
TypeScript
import { ResultItem } from "../types/result-types";
import { ExtractSelectResult, SelectProjections } from "./select-types";
import { IGroqBuilder, InferResultType } from "../types/public-types";
declare module "../groq-builder" {
interface GroqBuilder<TResult, TQueryConfig> {
/**
* Applies GROQ's `select` function, for conditional logic.
*
* The Condition strings are NOT strongly-typed. You can put any valid GROQ statement into these keys. See `selectByType` for a strongly-typed option.
*
* @example
* const qMovies = q.star.filterByType("movie").project({
* name: true,
* popularity: q.select({
* "popularity > 20": q.value("high"),
* "popularity > 10": q.value("medium"),
* }, q.value("low")),
* })
*/
select<TSelectProjections extends SelectProjections<ResultItem.Infer<TResult>, TQueryConfig>, TDefault extends null | IGroqBuilder = null>(selections: TSelectProjections, defaultSelection?: TDefault): GroqBuilder<ExtractSelectResult<TSelectProjections> | (TDefault extends null | undefined ? null : InferResultType<NonNullable<TDefault>>), TQueryConfig>;
}
}