store

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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(ctx context.Context, err error, message string, kvs ...any)
}

Logger defines an interface for logging errors with contextual information.

type Option

type Option[T any] func(*Store[T])

Option defines a function type for configuring the Store.

func WithLogger

func WithLogger[T any](logger Logger) Option[T]

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]) Create

func (s *Store[T]) Create(ctx context.Context, obj *T) error

Create inserts a new object into the database.

func (*Store[T]) DB

func (s *Store[T]) DB(ctx context.Context, wheres ...where.Where) *gorm.DB

db retrieves the database instance and applies the provided where conditions.

func (*Store[T]) Delete

func (s *Store[T]) Delete(ctx context.Context, opts *where.Options) error

Delete removes an object from the database based on the provided where options.

func (*Store[T]) Get

func (s *Store[T]) Get(ctx context.Context, opts *where.Options) (*T, error)

Get retrieves a single object from the database based on the provided where options.

func (*Store[T]) List

func (s *Store[T]) List(ctx context.Context, opts *where.Options) (count int64, ret []*T, err error)

List retrieves a list of objects from the database based on the provided where options.

func (*Store[T]) Update

func (s *Store[T]) Update(ctx context.Context, obj *T) error

Update modifies an existing object in the database.

Directories

Path Synopsis
logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL