Skip to content

Escaping parameters in an order-by clause #546

@emwalker

Description

@emwalker

This is a request for information and a possible feature request. I would like to be able to add an order-by clause with a parameter using the query builder DSL. E.g.,

mods = append(
  mods,
  qm.OrderBy("(topics.name ilike ?) desc, topics.name", searchString),
)

Looking at the code on master, this doesn't seem to be supported yet. Another possibility would be to be able to escape the string before it's passed to OrderBy:

mods = append(
  mods,
  qm.OrderBy(fmt.Sprintf("(topics.name ilike %s) desc, topics.name", qm.Escape(searchString)),
)

For this particular case, I would prefer to use the query builder rather than construct a raw query, as it makes it much easier to pick and choose what is to be added to the query.

Is there a recommended way of handling this situation?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions