备份代码
This commit is contained in:
parent
0d054c46fe
commit
207c3275b7
|
@ -0,0 +1,13 @@
|
|||
package contract
|
||||
|
||||
import "context"
|
||||
|
||||
const RepositoryKey = "hade:repository"
|
||||
|
||||
type Repository[T any, ID comparable] interface {
|
||||
Save(ctx context.Context, entity *T) error
|
||||
FindByID(ctx context.Context, id ID) (*T, error)
|
||||
FindByField(ctx context.Context, fieldName string, value any) ([]*T, error)
|
||||
FindByIDs(ctx context.Context, ids []ID) ([]*T, error)
|
||||
FindByFieldIn(ctx context.Context, fieldName string, values []any) ([]*T, error)
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"github.com/Superdanda/hade/framework"
|
||||
"github.com/Superdanda/hade/framework/contract"
|
||||
)
|
||||
|
||||
type RepositoryProvider struct{}
|
||||
|
||||
func (r RepositoryProvider) Register(container framework.Container) framework.NewInstance {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r RepositoryProvider) Boot(container framework.Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RepositoryProvider) IsDefer() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (r RepositoryProvider) Params(container framework.Container) []interface{} {
|
||||
return []interface{}{container}
|
||||
}
|
||||
|
||||
func (r RepositoryProvider) Name() string {
|
||||
return contract.RepositoryKey
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/Superdanda/hade/framework"
|
||||
"github.com/Superdanda/hade/framework/contract"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type HadeRepositoryService[T any, ID comparable] struct {
|
||||
container framework.Container
|
||||
cacheService contract.CacheService
|
||||
}
|
||||
|
||||
func NewHadeRepositoryService[T any, ID comparable](params ...interface{}) (interface{}, error) {
|
||||
if len(params) < 2 {
|
||||
return nil, errors.New("insufficient parameters")
|
||||
}
|
||||
container, ok := params[0].(framework.Container)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid container parameter")
|
||||
}
|
||||
cacheService, ok := params[1].(contract.CacheService)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid cacheService parameter")
|
||||
}
|
||||
return &HadeRepositoryService[T, ID]{
|
||||
container: container,
|
||||
cacheService: cacheService,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h *HadeRepositoryService[T, ID]) Save(ctx context.Context, entity *T) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (h HadeRepositoryService[T, ID]) FindByID(ctx context.Context, id ID) (*T, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (h HadeRepositoryService[T, ID]) FindByField(ctx context.Context, fieldName string, value any) ([]*T, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (h HadeRepositoryService[T, ID]) FindByIDs(ctx context.Context, ids []ID) ([]*T, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (h HadeRepositoryService[T, ID]) FindByFieldIn(ctx context.Context, fieldName string, values []any) ([]*T, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
type HadeCacheRepository[T any, ID comparable] struct {
|
||||
cacheService contract.CacheService
|
||||
}
|
Loading…
Reference in New Issue