Class: AbstractTargetBuilder

(abstract) AbstractTargetBuilder(entitynon-null)

An abstract base for builders that create `Message` instances which have a `Target` and a `FieldMask` as attributes.

The `Target` matching the builder configuration is accessed with `#getTarget()`, while the `FieldMask` is retrieved with `#getMask()`. The public API of this class is inspired by the SQL syntax. ```javascript select(CUSTOMER_TYPE) // returning descendant instance .byIds(getWestCoastCustomerIds()) .withMask(["name", "address", "email"]) .where([ Filters.eq("type", "permanent"), Filters.eq("discountPercent", 10), Filters.eq("companySize", Company.Size.SMALL) ]) .build() ```

Constructor

(abstract) new AbstractTargetBuilder(entitynon-null)

Parameters:
Name Type Description
entity Class.<Message> a Protobuf type of the target entities
Source:

Methods

_buildTarget() → {Target}

Creates a new target `Target` instance based on this builder configuration.
Source:
Returns:
a new target
Type
Target

(abstract) build() → {T}

A build method for creating instances of this builders target class.
Source:
Returns:
a new target class instance
Type
T

byIds(ids) → {this}

Sets an ID predicate of the `Query#getTarget()`. Makes the query return only the items identified by the provided IDs. Supported ID types are string, number, and Protobuf messages. All of the passed IDs must be of the same type. If number IDs are passed they are assumed to be of `int64` Protobuf type.
Parameters:
Name Type Description
ids !Array.<Message> | !Array.<Number> | !Array.<String> an array with identifiers to query
Source:
Throws:
  • if this method is executed more than once
  • if the provided IDs are not an instance of `Array`
  • if any of provided IDs are not an instance of supported types
  • if the provided IDs are not of the same type
Returns:
the current builder instance
Type
this

getMask() → {FieldMask}

Source:
Returns:
a fields mask set to this builder
Type
FieldMask

getTarget() → {Target}

Source:
Returns:
a target matching builders configuration
Type
Target

where(predicates) → {this}

Sets a field value predicate of the `Query#getTarget()`.

If there are no `Filter`s (i.e. the provided array is empty), all the records will be returned by executing the `Query`.

An array of predicates provided to this method are considered to be joined in a conjunction (using `CompositeFilter.CompositeOperator#ALL`). This means a record would match this query only if it matches all of the predicates.

Parameters:
Name Type Description
predicates !Array.<Filter> | Array.<CompositeFilter> the predicates to filter the requested items by
Source:
See:
  • Filters a convenient way to create `Filter` instances
Throws:
if this method is executed more than once
Returns:
self for method chaining
Type
this

withMask(fieldNamesnon-null) → {this}

Sets a Field Mask of the `Query`. The names of the fields must be formatted according to the `FieldMask` specification. If there are no fields (i.e. an empty array is passed), all the fields will be returned by query.
Parameters:
Name Type Description
fieldNames Array.<String>
Source:
See:
  • FieldMask specification for `FieldMask`
Throws:
if this method is executed more than once
Returns:
self for method chaining
Type
this