-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric_repository.go
58 lines (40 loc) · 1.88 KB
/
generic_repository.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
package ginboot
// GenericRepository defines the interface for a generic repository with string IDs
type GenericRepository[T any] interface {
// FindById finds a document by its string ID
FindById(id string) (T, error)
// FindAllById finds all documents with the given string IDs
FindAllById(ids []string) ([]T, error)
// Save saves a document
Save(doc T) error
// SaveOrUpdate saves or updates a document
SaveOrUpdate(doc T) error
// SaveAll saves multiple documents
SaveAll(docs []T) error
// Update updates an existing document
Update(doc T) error
// Delete deletes a document by its string ID
Delete(id string) error
// FindOneBy finds a document by a field value
FindOneBy(field string, value interface{}) (T, error)
// FindOneByFilters finds a document by multiple filters
FindOneByFilters(filters map[string]interface{}) (T, error)
// FindBy finds documents by a field value
FindBy(field string, value interface{}) ([]T, error)
// FindByFilters finds documents by multiple filters
FindByFilters(filters map[string]interface{}) ([]T, error)
// FindAll finds all documents
FindAll(options ...interface{}) ([]T, error)
// FindAllPaginated finds all documents with pagination
FindAllPaginated(pageRequest PageRequest) (PageResponse[T], error)
// FindByPaginated finds documents by filters with pagination
FindByPaginated(pageRequest PageRequest, filters map[string]interface{}) (PageResponse[T], error)
// CountBy counts documents by a field value
CountBy(field string, value interface{}) (int64, error)
// CountByFilters counts documents by multiple filters
CountByFilters(filters map[string]interface{}) (int64, error)
// ExistsBy checks if a document exists by a field value
ExistsBy(field string, value interface{}) (bool, error)
// ExistsByFilters checks if a document exists by multiple filters
ExistsByFilters(filters map[string]interface{}) (bool, error)
}