Documentation
¶
Index ¶
- type DataSource
- type DataSourceBuilder
- type Repository
- func (s *Repository[T]) Create(ctx context.Context, obj *T) error
- func (s *Repository[T]) Delete(ctx context.Context, id string) error
- func (s *Repository[T]) FindList(ctx context.Context) ([]T, error)
- func (s *Repository[T]) FindOne(ctx context.Context, id string) (*T, error)
- func (s *Repository[T]) Update(ctx context.Context, obj *T) error
- func (s *Repository[T]) WithTTL(ttl time.Duration) *Repository[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataSource ¶
type DataSource interface {
WithTTL(ttl time.Duration) DataSourceBuilder
// Record CRUD (stored as JSON string)
Create(ctx context.Context, key string, value any) error
Update(ctx context.Context, key string, value any) error
Delete(ctx context.Context, key string) error
Get(ctx context.Context, key string, dest any) error
// Index operations
AddToIndex(ctx context.Context, indexKey, id string, score float64) error
RemoveFromIndex(ctx context.Context, indexKey, id string) error
GetAllFromIndex(ctx context.Context, indexKey string, start, stop int64) ([]string, error)
// Atomic helpers (production-safe)
UpsertWithIndex(ctx context.Context, key, indexKey, id string, score float64, value any, ttl time.Duration) error
DeleteWithIndex(ctx context.Context, key, indexKey, id string) error
// Bulk read
GetAll(ctx context.Context, indexKey string, destSlice any) error
}
func NewDataSource ¶
func NewDataSource(rdb *redis.Client) DataSource
type DataSourceBuilder ¶
type DataSourceBuilder interface {
Create(ctx context.Context, key string, value any) error
Update(ctx context.Context, key string, value any) error
AddToIndex(ctx context.Context, indexKey, id string, score float64) error
UpsertWithIndex(ctx context.Context, key, indexKey, id string, score float64, value any) error
}
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
func NewRepository ¶
func NewRepository[T any]( ds DataSource, name string, env string, getIDFn func(*T) string, ) *Repository[T]
func (*Repository[T]) FindOne ¶
func (s *Repository[T]) FindOne(ctx context.Context, id string) (*T, error)
func (*Repository[T]) WithTTL ¶
func (s *Repository[T]) WithTTL(ttl time.Duration) *Repository[T]
Click to show internal directories.
Click to hide internal directories.