framework1/framework/contract/repository.go

34 lines
1.1 KiB
Go
Raw Normal View History

2024-10-29 23:02:40 +08:00
package contract
2024-10-30 16:56:41 +08:00
import (
"context"
"github.com/Superdanda/hade/framework"
)
2024-10-29 23:02:40 +08:00
const RepositoryKey = "hade:repository"
2024-10-30 16:56:41 +08:00
type RepositoryService interface {
GetGenericRepositoryByKey(key string) interface{}
GetGenericRepositoryMap() map[string]interface{}
GetContainer() framework.Container
}
type GenericRepository[T any, ID comparable] interface {
2024-10-29 23:02:40 +08:00
Save(ctx context.Context, entity *T) error
FindByID(ctx context.Context, id ID) (*T, error)
2024-10-30 16:56:41 +08:00
FindByField(ctx context.Context, fieldName string, value string) ([]*T, error)
2024-10-29 23:02:40 +08:00
FindByIDs(ctx context.Context, ids []ID) ([]*T, error)
2024-10-30 16:56:41 +08:00
FindByFieldIn(ctx context.Context, fieldName string, values []string) ([]*T, error)
}
type OrmRepository[T any, ID comparable] interface {
SaveToDB(entity *T) error
FindByIDFromDB(id ID) (*T, error)
FindByIDsFromDB(ids []ID) ([]*T, error)
GetPrimaryKey(entity *T) ID
GetBaseField() string
GetFieldQueryFunc(fieldName string) (func(value string) ([]*T, error), bool)
GetFieldInQueryFunc(fieldName string) (func(values []string) ([]*T, error), bool)
GetFieldValueFunc(fieldName string) (func(entity *T) string, bool)
2024-10-29 23:02:40 +08:00
}