pipelines library

Firestore Pipelines: queries made of stages and expressions that the server executes (Enterprise edition databases only).

Preview, Enterprise only: this API is experimental, may change in any release and needs a Firestore Enterprise edition database. Pipelines are always executed by the server: they do not use the local cache, do not see pending writes and cannot be listened to.

import 'package:cloud_firestore_dart/cloud_firestore_dart.dart';
import 'package:cloud_firestore_dart/pipelines.dart';

final snapshot = await firestore
    .pipeline()
    .collection('books')
    .where(field('rating').greaterThan(4))
    .aggregate([field('rating').average().as('avg')], groups: ['genre'])
    .execute();

The helper functions have short names (field, and, or, not, ...); import the library with a prefix if they clash with your own names.

Classes

AggregateFunction
A function that combines the values of many inputs into one, for use in Pipeline.aggregate.
AliasedAggregate
An AggregateFunction with a name, created with AggregateFunction.as.
AliasedExpression
An Expression with a name, created with Expression.as.
AliasedWindowFunction
A WindowFunction with a name, created with WindowFunction.as.
BooleanExpression
An expression that evaluates to a boolean: the condition of Pipeline.where.
Constant
A fixed value.
Expression
A value computed by the server while it runs a pipeline: a Field reference, a Constant, or a FunctionExpression over other expressions.
Field
A reference to a field of the input document.
FunctionExpression
A call of a server function.
Ordering
A sort key of Pipeline.sort, created with Expression.ascending or Expression.descending.
Pipeline
A query made of an ordered list of stages, executed by the server.
PipelineExplainOptions
Asks the server to explain how it runs a pipeline; pass it to Pipeline.execute. The explanation is in PipelineSnapshot.explainStats.
PipelineExplainStats
The explanation of a pipeline execution, as sent by the server.
PipelineResult
One row produced by a pipeline.
PipelineSnapshot
The results of executing a pipeline.
PipelineSource
Chooses where a Pipeline reads its input from. Get one with firestore.pipeline().
Selectable
An expression with a name: something that can be selected into a result.
VariableExpression
A reference to a variable: one defined with Pipeline.define, or the element of a lambda such as Expression.arrayFilter. Create it with variable(name).
WindowFrame
The inputs, relative to the current one, that a window function of Pipeline.addWindowFields is evaluated over.
WindowFunction
A function evaluated over a frame of inputs, for Pipeline.addWindowFields: a ranking function such as rank(), or an AggregateFunction with a frame (AggregateFunction.over).
WindowSpec
How Pipeline.addWindowFields groups and orders the inputs, and the default frame of its window functions.

Enums

OrderingDirection
The direction of an Ordering.
PipelineExplainMode
What the server does when it is asked to explain a pipeline.
PipelineExplainOutputFormat
The format of PipelineSnapshot.explainStats.
PipelineIndexMode
How the server chooses indexes for a pipeline.

Extensions

FirestorePipelines on FirebaseFirestore
Adds pipeline to FirebaseFirestore. Importing package:cloud_firestore_dart/pipelines.dart makes it available.
TransactionPipelines on Transaction
Adds execute to Transaction. Importing package:cloud_firestore_dart/pipelines.dart makes it available.

Functions

and(BooleanExpression first, BooleanExpression second, [List<BooleanExpression> more = const <BooleanExpression>[]]) → BooleanExpression
Whether all of the conditions hold.
array(List<Object?> elements) → FunctionExpression
An array built from elements, which may be values or expressions.
conditional(BooleanExpression condition, Object? thenValue, Object? elseValue) → FunctionExpression
thenValue if condition holds, elseValue otherwise.
constant(Object? value) → Constant
The fixed value: null, bool, int, double, String, DateTime, Timestamp, GeoPoint, Blob, VectorValue, DocumentReference, or lists and maps of those.
countAll() → AggregateFunction
Counts all inputs of an aggregation.
countIf(BooleanExpression condition) → AggregateFunction
Counts the inputs for which condition holds.
currentDocument() → FunctionExpression
The document that the enclosing stage is processing, as a map. Useful in Pipeline.define to hand the outer document to a subquery.
currentTimestamp() → FunctionExpression
The time at which the server evaluates the pipeline.
documentMatches(Object query) → BooleanExpression
Whether the document matches the full-text search query (a String in the search query language, or an expression that evaluates to one).
field(Object nameOrPath) → Field
A reference to the field nameOrPath: a dot-separated String or a FieldPath.
map(Map<String, Object?> entries) → FunctionExpression
A map built from entries, whose values may be values or expressions.
nor(BooleanExpression first, BooleanExpression second, [List<BooleanExpression> more = const <BooleanExpression>[]]) → BooleanExpression
Whether none of the conditions holds.
not(BooleanExpression condition) → BooleanExpression
The negation of condition.
or(BooleanExpression first, BooleanExpression second, [List<BooleanExpression> more = const <BooleanExpression>[]]) → BooleanExpression
Whether at least one of the conditions holds.
pipelineResultEqual(PipelineResult left, PipelineResult right) → bool
Whether left and right are the same row: the same document (or both not documents) of the same FirebaseFirestore instance, with equal data. The read times are not compared.
rand() → FunctionExpression
A random number between 0 (inclusive) and 1 (exclusive).
rank() → WindowFunction
The rank of the current input in its window partition, by the sort order of the window; tied inputs share a rank. For Pipeline.addWindowFields.
score() → FunctionExpression
The relevance of the document to the text conditions (such as documentMatches) of the enclosing Pipeline.search query; 0 when the query has none. Only allowed in a search stage.
switchOn(BooleanExpression condition, Object? result, [List<Object?> others = const <Object?>[]]) → FunctionExpression
The result that follows the first condition that holds.
variable(String name) → VariableExpression
A reference to the variable name, defined with Pipeline.define in this pipeline or in a pipeline that contains this one as a subquery.
xor(BooleanExpression first, BooleanExpression second, [List<BooleanExpression> more = const <BooleanExpression>[]]) → BooleanExpression
Whether an odd number of the conditions hold.