Skip to content

tyneq


tyneq / QueryPlanCompiler

Class: QueryPlanCompiler

Defined in: src/queryplan/compiler/QueryPlanCompiler.ts:59

Compiles a query plan tree into an executable TyneqSequence.

Remarks

Walks the QueryPlanNode chain from source to terminal, reconstructing each operator by looking it up in the OperatorRegistry and applying it to the compiled source. An optional list of QueryPlanTransformer instances runs before compilation, allowing optimization or rewriting of the plan.

Example

ts
import { Tyneq, tyneqQueryNode, QueryPlanCompiler, QueryPlanOptimizer } from "tyneq";

const seq = Tyneq.from([1, 2, 3]).where(x => x > 1).select(x => x * 2);
const compiler = new QueryPlanCompiler([new QueryPlanOptimizer()]);
const result = compiler.compile(seq[tyneqQueryNode]!);
result.toArray(); // -> [4, 6]

Constructors

Constructor

new QueryPlanCompiler(transformers?): QueryPlanCompiler

Defined in: src/queryplan/compiler/QueryPlanCompiler.ts:62

Parameters

ParameterTypeDefault value
transformersIterable<QueryPlanTransformer>[]

Returns

QueryPlanCompiler

Methods

compile()

compile<T, TResult>(node, options?): TResult

Defined in: src/queryplan/compiler/QueryPlanCompiler.ts:80

Compile a query plan into an executable sequence.

Runs all registered transformers before compiling. Use compileRaw to skip the transform phase when the plan is already optimised.

Type Parameters

Type ParameterDefault type
Tunknown
TResult extends TyneqSequence<T>TyneqSequence<T>

Parameters

ParameterTypeDescription
nodeIQueryNodeThe root node of the query plan to compile.
options?CompileOptionsOptional compile-time overrides. Use options.source to supply a different data source than the one stored in the plan.

Returns

TResult

The compiled sequence typed as TyneqSequence<T> by default. If you know the plan ends in an operator that returns a subtype (e.g. orderBy -> TyneqOrderedSequence, memoize -> TyneqCachedSequence), supply TResult explicitly: compiler.compile<number, TyneqOrderedSequence<number>>(node).


compileRaw()

compileRaw<T, TResult>(node, options?): TResult

Defined in: src/queryplan/compiler/QueryPlanCompiler.ts:105

Compile a pre-optimised query plan into an executable sequence, skipping the transform phase.

Type Parameters

Type ParameterDefault type
Tunknown
TResult extends TyneqSequence<T>TyneqSequence<T>

Parameters

ParameterTypeDescription
nodeIQueryNodeThe root node of the already-transformed query plan to compile.
options?CompileOptionsOptional compile-time overrides. Use options.source to supply a different data source than the one stored in the plan.

Returns

TResult

Remarks

Use this overload when you have already run transformers externally (or deliberately want to bypass them) and want to compile the node as-is. Equivalent to constructing a QueryPlanCompiler with no transformers and calling compile().