Skip to content

Commit

Permalink
♻️ Refactor(paginate.go): add id only on firt column
Browse files Browse the repository at this point in the history
  • Loading branch information
booscaaa committed Nov 10, 2023
1 parent 9ee7769 commit 017ec7f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions v2/paginate/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,18 @@ func GenerateSQL(params *paginQueryParams) (string, []interface{}) {
columnName := getFieldName(column, "json", "paginate", params.Struct)
if columnName != "" && idColumnName != "" {
argNum := nextArg()
argNumNext := nextArg()
sortClauses = append(sortClauses, fmt.Sprintf("(((%s = $%d) OR (%s %s $%d)) AND %s %s $%d)",
columnName, argNum, columnName, getComparisonOperator(params.SortDirections[i]), argNum, idColumnName, getComparisonOperator(params.SortDirections[i]), argNumNext))
args[len(args)-2] = params.mapArgs[column]
args[len(args)-1] = params.mapArgs["id"]

if i == 0 {
argNumNext := nextArg()
sortClauses = append(sortClauses, fmt.Sprintf("(((%s = $%d) OR (%s %s $%d)) AND %s %s $%d)",
columnName, argNum, columnName, getComparisonOperator(params.SortDirections[i]), argNum, idColumnName, getComparisonOperator(params.SortDirections[i]), argNumNext))
args[len(args)-2] = params.mapArgs[column]
args[len(args)-1] = params.mapArgs["id"]
} else {
sortClauses = append(sortClauses, fmt.Sprintf("(((%s = $%d) OR (%s %s $%d))",
columnName, argNum, columnName, getComparisonOperator(params.SortDirections[i]), argNum))
args[len(args)-2] = params.mapArgs[column]
}
}
}
if len(sortClauses) > 0 {
Expand Down

0 comments on commit 017ec7f

Please sign in to comment.