/
options.go
53 lines (48 loc) · 1.6 KB
/
options.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package gormstore
import (
"github.com/jkaveri/goflexstore/converter"
gormquery "github.com/jkaveri/goflexstore/gorm/query"
"github.com/jkaveri/goflexstore/store"
)
// Option is a function that modifies the store.
// It is used to set various configuration options for the Store at the time of its creation.
type Option[Entity store.Entity[ID], DTO store.Entity[ID], ID comparable] func(*Store[Entity, DTO, ID])
// WithBatchSize sets the batch size for batch operations in the store.
// batchSize specifies the number of records to be processed in a single batch during batch operations.
func WithBatchSize[
Entity store.Entity[ID],
DTO store.Entity[ID],
ID comparable,
](
batchSize int,
) Option[Entity, DTO, ID] {
return func(s *Store[Entity, DTO, ID]) {
s.BatchSize = batchSize
}
}
// WithConverter sets the converter used for transforming between entity and DTO types.
// converter is an instance of a converter that can convert between the entity and DTO types.
func WithConverter[
Entity store.Entity[ID],
DTO store.Entity[ID],
ID comparable,
](
converter converter.Converter[Entity, DTO, ID],
) Option[Entity, DTO, ID] {
return func(s *Store[Entity, DTO, ID]) {
s.Converter = converter
}
}
// WithScopeBuilderOption sets the scope builder options for the store.
// options are a variadic list of options that configure the behavior of the scope builder.
func WithScopeBuilderOption[
Entity store.Entity[ID],
DTO store.Entity[ID],
ID comparable,
](
options ...gormquery.Option,
) Option[Entity, DTO, ID] {
return func(s *Store[Entity, DTO, ID]) {
s.ScopeBuilder = gormquery.NewBuilder(options...)
}
}