diff --git a/examples/23_custom_query_language.html b/examples/23_custom_query_language.html index 9cbe2fd..c6e8d43 100644 --- a/examples/23_custom_query_language.html +++ b/examples/23_custom_query_language.html @@ -72,7 +72,14 @@ } if (projection) { - query = `_.map(${query}, item => _.pick(item, ${JSON.stringify(projection.fields)}))` + // It is possible to make a util function "pickFlat" + // and use that when building the query to make it more readable. + const fields = projection.fields.map(field => { + const name = _.last(field.split('.')) + return ` '${name}': _.get(item, '${field}')` + }) + + query = `_.map(${query}, item => ({\n${fields.join(',\n')}})\n)` } return query