diff --git a/examples/23_custom_query_language.html b/examples/23_custom_query_language.html index c6e8d43..33c21e2 100644 --- a/examples/23_custom_query_language.html +++ b/examples/23_custom_query_language.html @@ -74,12 +74,16 @@ if (projection) { // 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)` + if (projection.fields.length > 1) { + 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)` + } else { + const field = projection.fields[0] + query = `_.map(${query}, item => _.get(item, '${field}'))` + } } return query