/
key_words_group.go
21 lines (18 loc) · 997 Bytes
/
key_words_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package linq
import (
"strings"
)
// GroupBy groups the elements in the database container based on the specified columns.
// It takes a slice of strings representing the columns to group by.
// It returns the updated database container after grouping the elements based on the specified columns.
func (container DB[T]) GroupBy(columns []string) DB[T] {
container.db = container.db.Group(strings.Join(columns, ", "))
return container
}
// GroupByHaving groups the elements in the database container based on the specified columns and condition.
// It takes a slice of strings representing the columns to group by and a QueryString representing the condition.
// It returns the updated database container after grouping the elements based on the specified columns and condition.
func (container DB[T]) GroupByHaving(columns []string, condition QueryString) DB[T] {
container.db = container.db.Group(strings.Join(columns, ", ")).Having(condition.Query, condition.Args...)
return container
}