projectFields
Function: projectFields()
projectFields<
T>(object,paths):Partial<T>
Defined in: packages/ql/src/projection.ts:105
Keep only some fields of an object: the projection of a SELECT a, b.c field list
b.ckeeps{ b: { c } }; sibling paths merge (b.c, b.d), and a path listed with one of its parents (b, b.c) keeps the whole parent. Duplicates are ignored.- A path through an array applies to each element:
tags.nameontags: [{ name, color }]keepstags: [{ name }]. - A path through a scalar or
nullselects nothing: the field is omitted (an array element is dropped). An object on the path is kept, even when none of its fields is selected. - A missing value is omitted, an existing
nullis kept. - Keys keep the order of the object, not the order of the paths.
- A path with a
__proto__,constructororprototypesegment is ignored.
The object is not changed. Values selected whole are returned by reference, not copied.
Type Parameters
T
T = any
Parameters
object
T
the object to project (an array is projected element by element)
paths
Iterable<string>
dotted field paths to keep
Returns
Partial<T>
a new object holding the selected fields; a value that is not an object is returned as is