Documentation
¶
Overview ¶
nolint: dupl
Package store defines the storage interface for miniblog.
nolint: dupl
nolint: dupl
Index ¶
Constants ¶
This section is empty.
Variables ¶
ProviderSet 是一个 Wire 的 Provider 集合,用于声明依赖注入的规则. 包含 NewStore 构造函数,用于生成 datastore 实例. wire.Bind 用于将接口 IStore 与具体实现 *datastore 绑定, 从而在依赖 IStore 的地方,能够自动注入 *datastore 实例.
View Source
var (
// 全局变量,方便其它包直接调用已初始化好的 datastore 实例.
S *datastore
)
Functions ¶
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.
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 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 层所实现的方法.
Click to show internal directories.
Click to hide internal directories.