Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sort dialect-unspecific, allow multiple orders #33

Open
mkg20001 opened this issue Feb 25, 2023 · 0 comments
Open

Make sort dialect-unspecific, allow multiple orders #33

mkg20001 opened this issue Feb 25, 2023 · 0 comments

Comments

@mkg20001
Copy link

Currently sort is dialect-specific (as it's being passed into the query as a raw string, therefore subject to dialects quoting rules) and being limited to one key

One idea that would work is to convert sort to accepting an array [[key, 'ASC/DESC']] and then iterate over that like this

const schema = Joi.array().items(Joi.array().ordered(Joi.string().valid('id', 'etc').required(), Joi.string().valid('asc', 'desc').default('asc')).required())
const { error, validated } = schema.validate(sortParam)

if (error) throw error

for (const sort of validated) {
  query = query.orderBy(sort[0], sort[1])
}

For backwards compatibility the new behaviour could be a flag or switched with sortParam.startsWith('[') (where the old schema is converted to the new one internally)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant