store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Store 层

因为 Store 代码相对不易变,所以,Store 层很少会随着项目迭代,衍生出V2版本,所以Store层只需要一个版本即可。

Documentation

Overview

nolint: dupl

Package store defines the storage interface for miniblog.

nolint: dupl

nolint: dupl

Index

Constants

This section is empty.

Variables

View Source
var ProviderSet = wire.NewSet(NewStore, wire.Bind(new(IStore), new(*datastore)))

ProviderSet 是一个 Wire 的 Provider 集合,用于声明依赖注入的规则. 包含 NewStore 构造函数,用于生成 datastore 实例. wire.Bind 用于将接口 IStore 与具体实现 *datastore 绑定, 从而在依赖 IStore 的地方,能够自动注入 *datastore 实例.

View Source
var (

	// 全局变量,方便其它包直接调用已初始化好的 datastore 实例.
	S *datastore
)

Functions

func NewStore

func NewStore(db *gorm.DB) *datastore

NewStore 创建一个 IStore 类型的实例.

Types

type ConcretePostExpansion

type ConcretePostExpansion interface{}

ConcretePostExpansion 定义了帖子操作的附加方法.

type ConcretePostStore

type ConcretePostStore interface {
	Create(ctx context.Context, obj *model.PostM) error
	Update(ctx context.Context, obj *model.PostM) error
	Delete(ctx context.Context, opts *where.Options) error
	Get(ctx context.Context, opts *where.Options) (*model.PostM, error)
	List(ctx context.Context, opts *where.Options) (int64, []*model.PostM, error)

	ConcretePostExpansion
}

ConcretePostStore 定义了 post 模块在 store 层所实现的方法.

type IStore

type IStore interface {
	// 返回 Store 层的 *gorm.DB 实例,在少数场景下会被用到.
	DB(ctx context.Context, wheres ...where.Where) *gorm.DB
	TX(ctx context.Context, fn func(ctx context.Context) error) error

	User() UserStore
	Post() PostStore
	// ConcretePosts 是一个示例 store 实现,用来演示在 Go 中如何直接与 DB 交互.
	ConcretePost() ConcretePostStore
}

IStore 定义了 Store 层需要实现的方法.

type Logger

type Logger struct{}

Logger is a logger that implements the Logger interface. It uses the log package to log error messages with additional context.

func NewLogger

func NewLogger() *Logger

NewLogger creates and returns a new instance of Logger.

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, err error, msg string, kvs ...any)

Error logs an error message with the provided context using the log package.

type PostExpansion

type PostExpansion interface{}

PostExpansion 定义了帖子操作的附加方法.

type PostStore

type PostStore interface {
	Create(ctx context.Context, obj *model.PostM) error
	Update(ctx context.Context, obj *model.PostM) error
	Delete(ctx context.Context, opts *where.Options) error
	Get(ctx context.Context, opts *where.Options) (*model.PostM, error)
	List(ctx context.Context, opts *where.Options) (int64, []*model.PostM, error)

	PostExpansion
}

PostStore 定义了 post 模块在 store 层所实现的方法.

type UserExpansion

type UserExpansion interface{}

UserExpansion 定义了用户操作的附加方法. nolint: iface

type UserStore

type UserStore interface {
	Create(ctx context.Context, obj *model.UserM) error
	Update(ctx context.Context, obj *model.UserM) error
	Delete(ctx context.Context, opts *where.Options) error
	Get(ctx context.Context, opts *where.Options) (*model.UserM, error)
	List(ctx context.Context, opts *where.Options) (int64, []*model.UserM, error)

	UserExpansion
}

UserStore 定义了 user 模块在 store 层所实现的方法.

Jump to

Keyboard shortcuts

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