Description
It would be helpful if Winnow supported the "NULLS LAST" clause that is available with SQL "ORDER BY" clauses.
When our provider, koop-provider-marklogic (https://github.com/koopjs/koop-provider-marklogic), retrieves paged data and there is an "ORDER BY" field that contains NULL values, then there is likely to be a page of data with a mix of values and nulls. The orderBy clause generated by "createOrderByClause" in "order-by.js" does not recognize the "NULLS LAST" clause and therefore on a page with mixed values, the NULLS appear first in the list, even though they appear last in query response from the database.
We would like to be able to include "NULLS LAST" in the "ORDER BY" clause and then have the SQL generated in Winnow respect that.
I'm not intending to propose the right solution here, but I did find out that the below change supports what we're looking for
function createOrderByClause (options = {}) {
const { order: orderByArray, esri, aggregates } = options;
if (!orderByArray) return '';
const selector = esri ? 'attributes' : 'properties';
const orderByClause = orderByArray.map(orderBy => {
let [field, direction = 'ASC'] = orderBy.split(' ');
// New code
if (orderBy.toUpperCase().endsWith("NULLS LAST")) {
direction += " NULLS LAST";
}
// End of new code
if (shouldFormatForAggregationQuery(field, aggregates)) {
return `\`${field}\` ${direction.toUpperCase()}`;
}
return `${selector}->\`${field}\` ${direction.toUpperCase()}`;
}).join(', ');
return ` ORDER BY ${orderByClause}`;
}