Documentation ¶
Overview ¶
Copyright 2022 Lingfei Kong <colin404@foxmail.com>. All rights reserved. Use of this source code is governed by a MIT style license that can be found in the LICENSE file. The original repo for this file is https://github.com/superproj/onex.
Index ¶
- type DBProvider
- type Logger
- type Option
- type Store
- func (s *Store[T]) Create(ctx context.Context, obj *T) error
- func (s *Store[T]) Delete(ctx context.Context, opts *where.Options) error
- func (s *Store[T]) Get(ctx context.Context, opts *where.Options) (*T, error)
- func (s *Store[T]) List(ctx context.Context, opts *where.Options) (count int64, ret []*T, err error)
- func (s *Store[T]) Update(ctx context.Context, obj *T) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBProvider ¶
type DBProvider interface { // DB returns the database instance for the given context. DB(ctx context.Context, wheres ...where.Where) *gorm.DB }
DBProvider defines an interface for providing a database connection.
type Logger ¶
type Logger interface { // Error logs an error message with the associated context. Error(err error, message string, kvs ...any) }
Logger defines an interface for logging errors with contextual information.
type Option ¶
Option defines a function type for configuring the Store.
func WithLogger ¶
WithLogger returns an Option function that sets the provided Logger to the Store for logging purposes.
type Store ¶
type Store[T any] struct { // contains filtered or unexported fields }
Store represents a generic data store with logging capabilities.
func NewStore ¶
func NewStore[T any](storage DBProvider, logger Logger) *Store[T]
NewStore creates a new instance of Store with the provided DBProvider.
func (*Store[T]) Delete ¶
Delete removes an object from the database based on the provided where options.
func (*Store[T]) Get ¶
Get retrieves a single object from the database based on the provided where options.