Gorm order by with params

2 weeks ago 21
ARTICLE AD BOX

Is there a secure/blessed/correct way to pass params into a golang Gorm SQL query ORDER BY clause?

This is what I want to do:

tx.Order(`array_position(?, id)`, modelIDs)

The modelID slice is sorted already (by an Elastic Search ranking), so I want to pass that into SQL Order. but Order doesn't accept params.

I went looking for ways in Gorm to assemble my own clauses, but it's getting into hacky, cursed code. Is there a way, and I'm just not searching for the right terms?

Read Entire Article