forked from yaitoo/sqle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_option.go
More file actions
39 lines (32 loc) · 917 Bytes
/
Copy pathquery_option.go
File metadata and controls
39 lines (32 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package sqle
import (
"time"
"github.com/yaitoo/sqle/shardid"
)
type QueryOption[T any] func(q *Query[T])
func WithMonths[T any](start, end time.Time) QueryOption[T] {
return func(q *Query[T]) {
for t := start; !t.After(end); t = t.AddDate(0, 1, 0) {
q.withRotatedTables = append(q.withRotatedTables, shardid.FormatMonth(t))
}
}
}
func WithWeeks[T any](start, end time.Time) QueryOption[T] {
return func(q *Query[T]) {
for t := start; !t.After(end); t = t.AddDate(0, 0, 7) {
q.withRotatedTables = append(q.withRotatedTables, shardid.FormatWeek(t))
}
}
}
func WithDays[T any](start, end time.Time) QueryOption[T] {
return func(q *Query[T]) {
for t := start; !t.After(end); t = t.AddDate(0, 0, 1) {
q.withRotatedTables = append(q.withRotatedTables, shardid.FormatDay(t))
}
}
}
func WithQueryer[T any](qr Queryer[T]) QueryOption[T] {
return func(q *Query[T]) {
q.queryer = qr
}
}