-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.go
85 lines (69 loc) · 1.86 KB
/
repo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package repository
import (
"context"
"reflect"
)
type Repository[E any] interface {
GetEntityType() reflect.Type
}
type BaseRepository[E any] struct {
}
func (repo BaseRepository[E]) GetEntityType() reflect.Type {
return reflect.TypeOf(repo)
}
var _ Repository[any] = (*BaseRepository[any])(nil)
type Inserter[E any] interface {
Repository[E]
Insert(ctx context.Context, entity *E) error
}
type Deleter[E any] interface {
Repository[E]
Delete(ctx context.Context, entity *E) error
DeleteById(ctx context.Context, id any) error
}
type Updater[E any] interface {
Repository[E]
Update(ctx context.Context, entity *E) error
}
type Lister[E any] interface {
Repository[E]
List(ctx context.Context) ([]E, error)
}
type Getter[E any] interface {
Repository[E]
Get(ctx context.Context, id any) (E, error)
}
type CrudRepository[E any] interface {
Repository[E]
Inserter[E]
Deleter[E]
Updater[E]
Lister[E]
Getter[E]
}
type Finder[E any] interface {
Repository[E]
Find(ctx context.Context, specifications ...Specification) ([]E, error)
}
type Counter[E any] interface {
Repository[E]
Count(ctx context.Context, specifications ...Specification) (i int64, err error)
}
type AbstractRepository[E any] interface {
CrudRepository[E]
Finder[E]
Counter[E]
}
type GenericRepository[E any] interface {
Insert(ctx context.Context, entity *E) error
Delete(ctx context.Context, entity *E) error
DeleteById(ctx context.Context, id any) error
Update(ctx context.Context, entity *E) error
Get(ctx context.Context, id any) (E, error)
List(ctx context.Context) ([]E, error)
}
type ComplexRepository[E any] interface {
Find(ctx context.Context, specifications ...Specification) ([]E, error)
FindWithLimit(ctx context.Context, limit int, offset int, specifications ...Specification) ([]E, error)
Count(ctx context.Context, specifications ...Specification) (i int64, err error)
}