store

package
v0.2.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 5 Imported by: 0

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

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

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]) 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
Package where is used to handle GORM's Where query conditions.
Package where is used to handle GORM's Where query conditions.

Jump to

Keyboard shortcuts

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