Skip to content

Commit 0528c9d

Browse files
committed
Additional comments within gorm search query to try to aid benchmarks
1 parent fae511a commit 0528c9d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

utils/gorm_search_query.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ func GormSearchQuery[p interface{}](params p) (string, []interface{}) {
3737
var conditions []string
3838
var args []interface{}
3939

40+
// While it looks like this code could be improved with caching, the advantage would be ~80 ns/op,
41+
// which compared to the rest of the function, the code would be more complex and harder to read/maintain.
4042
v := reflect.ValueOf(params)
4143
t := v.Type()
4244

4345
for i := 0; i < t.NumField(); i++ {
4446
fieldValue := v.Field(i)
4547
fieldType := t.Field(i)
48+
49+
// The use of the query tag allows any struct, even the GORM model struct, to be used with this function.
4650
queryTag := fieldType.Tag.Get("query")
4751

4852
// Skip if no tag is provided or the field value is empty
@@ -53,7 +57,6 @@ func GormSearchQuery[p interface{}](params p) (string, []interface{}) {
5357
conditions = append(conditions, queryTag)
5458
args = append(args, fieldValue.Interface())
5559
}
56-
5760
if len(conditions) > 0 {
5861
queryStr := "(" + strings.Join(conditions, " AND ") + ")"
5962

0 commit comments

Comments
 (0)