This is a very small peeve, and we should really be migrating to Bun, but go-pg is lacking a method that works like:
OrderBy( field, direction )
What it has instead is a method that takes the whole clause as string, like this:
Order( "my_field ASC" )
So code that uses it ends up frequently looking like
Order( fmt.Sprintf( "%s %s", column, order ) )
What happens internally? The Order() function parses the string and then calls
Query.OrderExpr( "? ?", pg.Ident(column), pg.Safe(order) )
https://github.com/go-pg/pg/blob/bce00adc25696cc87008ccc4daf10f6350bbdae8/orm/query.go#L721
So, the entire process looks like:
OK, OK, maybe step 3 adds some quoting that wasn't there already. But today I finally wrote a utility function to avoid this round-trip through steps 1 and 2 by copying the OrderExpr call.
[#]golang #postgres
=> More informations about this toot | More toots from markgritter@mathstodon.xyz
text/gemini
This content has been proxied by September (3851b).