The new projection feature in v10 is great. But transforming data during projection could be so much more convenient if we could apply udfs or lambdas at arbitrary parts of the projection.
Sometimes I need to do some data transformation on a property. If the property I need to convert is several nestings deep then i can’t really use projection to its full potential.
Current:
let stats = data.stats.map(stat=>(
let entry = stat.entry
let rooms = Rooms.byEntry(entry).map(room=>room {
id,
name,
date: Date.fromString(room.dateAsString)
})
stat {
entry: entry {
id,
rooms: rooms.paginate()
}
}
))
data {
stats: stats
}
vs proposed feature
data {
stats {
entry {
id,
rooms: (Rooms.byEntry(.) {
id,
name,
date: Date.fromString(.dateAsString)
}).paginate()
}
}
}
The way v10 works currently requires more code, and is harder to understand what is going on. It gets more confusing if you have a larger data structure with more transformations.
In the proposal above, Rooms.byEntry(.)
is an index that gets the set of rooms for an entry. It would receive the current entry because I am passing in the .
which is something I made up to represent the entire object/document of the current projection context.