store

package
v0.0.0-...-49bf833 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 8 Imported by: 0

README

store layer

  • 仓库层

开发流程

  • 使用单例工厂模式
  • 创建一个结构体: 用来创建 store 层实例
    • store 建立在 *gorm.DB 之上
  • 创建一个 New 函数: 初始化 store 层实例
  • 创建一个包级别的 store 层变量: 为了方便调用 store 层实例
    • S *datastore
  • 创建一个 sync.Once 变量: 为了避免实例被多次创建,
    • once sync.Once

设计思想

  • store.go 中定义 store 层需要实现的模块
    • user.go 中定义 user 模块需要在 store 层所实现的方法, 并实现
  • 从物理上分割多表的代码实现,使代码更易阅读及维护
  • store 层依赖 *gorm.DB 对象, 因为其是项目无关的,可供第三方引用的动作,所以将其以包的形式放置在 pkg
  • initStore 具体实现放置在 helper.go 之中, 使 main 保持简洁

Documentation

Overview

Package store defines the store layer of dazBlog

Package store is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (

	// S global variable used for easy access to the initialized instance of store layer by other packages
	S *datastore
)

Functions

func NewStore

func NewStore(db *gorm.DB) *datastore

NewStore create an instance of type IStore

Types

type AIStore

type AIStore interface {
	Create(ctx context.Context, ai *model.AIM) error
	Get(ctx context.Context, username string, postID string) (*model.AIM, error)
	Update(ctx context.Context, ai *model.AIM) error
	List(ctx context.Context, username string, offset, limit int) (int64, []*model.AIM, error)
	Delete(ctx context.Context, username string, postID string) error
}

type IStore

type IStore interface {
	DB() *gorm.DB
	Users() UserStore
	Posts() PostStore
	AIs() AIStore
}

IStore defines the methods that need to be implemented by the Store layer such as IStore defines Users, Users defines the specific methods

type MockAIStore

type MockAIStore struct {
	// contains filtered or unexported fields
}

MockAIStore is a mock of AIStore interface.

func NewMockAIStore

func NewMockAIStore(ctrl *gomock.Controller) *MockAIStore

NewMockAIStore creates a new mock instance.

func (*MockAIStore) Create

func (m *MockAIStore) Create(arg0 context.Context, arg1 *model.AIM) error

Create mocks base method.

func (*MockAIStore) Delete

func (m *MockAIStore) Delete(arg0 context.Context, arg1, arg2 string) error

Delete mocks base method.

func (*MockAIStore) EXPECT

func (m *MockAIStore) EXPECT() *MockAIStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAIStore) Get

func (m *MockAIStore) Get(arg0 context.Context, arg1, arg2 string) (*model.AIM, error)

Get mocks base method.

func (*MockAIStore) List

func (m *MockAIStore) List(arg0 context.Context, arg1 string, arg2, arg3 int) (int64, []*model.AIM, error)

List mocks base method.

func (*MockAIStore) Update

func (m *MockAIStore) Update(arg0 context.Context, arg1 *model.AIM) error

Update mocks base method.

type MockAIStoreMockRecorder

type MockAIStoreMockRecorder struct {
	// contains filtered or unexported fields
}

MockAIStoreMockRecorder is the mock recorder for MockAIStore.

func (*MockAIStoreMockRecorder) Create

func (mr *MockAIStoreMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call

Create indicates an expected call of Create.

func (*MockAIStoreMockRecorder) Delete

func (mr *MockAIStoreMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockAIStoreMockRecorder) Get

func (mr *MockAIStoreMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockAIStoreMockRecorder) List

func (mr *MockAIStoreMockRecorder) List(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

List indicates an expected call of List.

func (*MockAIStoreMockRecorder) Update

func (mr *MockAIStoreMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call

Update indicates an expected call of Update.

type MockIStore

type MockIStore struct {
	// contains filtered or unexported fields
}

MockIStore is a mock of IStore interface.

func NewMockIStore

func NewMockIStore(ctrl *gomock.Controller) *MockIStore

NewMockIStore creates a new mock instance.

func (*MockIStore) AIs

func (m *MockIStore) AIs() AIStore

AIs mocks base method.

func (*MockIStore) DB

func (m *MockIStore) DB() *gorm.DB

DB mocks base method.

func (*MockIStore) EXPECT

func (m *MockIStore) EXPECT() *MockIStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockIStore) Posts

func (m *MockIStore) Posts() PostStore

Posts mocks base method.

func (*MockIStore) Users

func (m *MockIStore) Users() UserStore

Users mocks base method.

type MockIStoreMockRecorder

type MockIStoreMockRecorder struct {
	// contains filtered or unexported fields
}

MockIStoreMockRecorder is the mock recorder for MockIStore.

func (*MockIStoreMockRecorder) AIs

func (mr *MockIStoreMockRecorder) AIs() *gomock.Call

AIs indicates an expected call of AIs.

func (*MockIStoreMockRecorder) DB

DB indicates an expected call of DB.

func (*MockIStoreMockRecorder) Posts

func (mr *MockIStoreMockRecorder) Posts() *gomock.Call

Posts indicates an expected call of Posts.

func (*MockIStoreMockRecorder) Users

func (mr *MockIStoreMockRecorder) Users() *gomock.Call

Users indicates an expected call of Users.

type MockPostStore

type MockPostStore struct {
	// contains filtered or unexported fields
}

MockPostStore is a mock of PostStore interface.

func NewMockPostStore

func NewMockPostStore(ctrl *gomock.Controller) *MockPostStore

NewMockPostStore creates a new mock instance.

func (*MockPostStore) Create

func (m *MockPostStore) Create(arg0 context.Context, arg1 *model.PostM) error

Create mocks base method.

func (*MockPostStore) Delete

func (m *MockPostStore) Delete(arg0 context.Context, arg1 string, arg2 []string) error

Delete mocks base method.

func (*MockPostStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPostStore) Get

func (m *MockPostStore) Get(arg0 context.Context, arg1, arg2 string) (*model.PostM, error)

Get mocks base method.

func (*MockPostStore) List

func (m *MockPostStore) List(arg0 context.Context, arg1 string, arg2, arg3 int) (int64, []*model.PostM, error)

List mocks base method.

func (*MockPostStore) Update

func (m *MockPostStore) Update(arg0 context.Context, arg1 *model.PostM) error

Update mocks base method.

type MockPostStoreMockRecorder

type MockPostStoreMockRecorder struct {
	// contains filtered or unexported fields
}

MockPostStoreMockRecorder is the mock recorder for MockPostStore.

func (*MockPostStoreMockRecorder) Create

func (mr *MockPostStoreMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call

Create indicates an expected call of Create.

func (*MockPostStoreMockRecorder) Delete

func (mr *MockPostStoreMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockPostStoreMockRecorder) Get

func (mr *MockPostStoreMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockPostStoreMockRecorder) List

func (mr *MockPostStoreMockRecorder) List(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

List indicates an expected call of List.

func (*MockPostStoreMockRecorder) Update

func (mr *MockPostStoreMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call

Update indicates an expected call of Update.

type MockUserStore

type MockUserStore struct {
	// contains filtered or unexported fields
}

MockUserStore is a mock of UserStore interface.

func NewMockUserStore

func NewMockUserStore(ctrl *gomock.Controller) *MockUserStore

NewMockUserStore creates a new mock instance.

func (*MockUserStore) Create

func (m *MockUserStore) Create(arg0 context.Context, arg1 *model.UserM) error

Create mocks base method.

func (*MockUserStore) Delete

func (m *MockUserStore) Delete(arg0 context.Context, arg1 string) error

Delete mocks base method.

func (*MockUserStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockUserStore) Get

func (m *MockUserStore) Get(arg0 context.Context, arg1 string) (*model.UserM, error)

Get mocks base method.

func (*MockUserStore) List

func (m *MockUserStore) List(arg0 context.Context, arg1, arg2 int) (int64, []*model.UserM, error)

List mocks base method.

func (*MockUserStore) Update

func (m *MockUserStore) Update(arg0 context.Context, arg1 *model.UserM) error

Update mocks base method.

type MockUserStoreMockRecorder

type MockUserStoreMockRecorder struct {
	// contains filtered or unexported fields
}

MockUserStoreMockRecorder is the mock recorder for MockUserStore.

func (*MockUserStoreMockRecorder) Create

func (mr *MockUserStoreMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call

Create indicates an expected call of Create.

func (*MockUserStoreMockRecorder) Delete

func (mr *MockUserStoreMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockUserStoreMockRecorder) Get

func (mr *MockUserStoreMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockUserStoreMockRecorder) List

func (mr *MockUserStoreMockRecorder) List(arg0, arg1, arg2 interface{}) *gomock.Call

List indicates an expected call of List.

func (*MockUserStoreMockRecorder) Update

func (mr *MockUserStoreMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call

Update indicates an expected call of Update.

type PostStore

type PostStore interface {
	Create(ctx context.Context, user *model.PostM) error
	Get(ctx context.Context, username string, postID string) (*model.PostM, error)
	Update(ctx context.Context, user *model.PostM) error
	List(ctx context.Context, username string, offset, limit int) (int64, []*model.PostM, error)
	Delete(ctx context.Context, username string, postIDs []string) error
}

PostStore defines the methods that need to be implemented by the post model in the store layer

type UserStore

type UserStore interface {
	Create(ctx context.Context, user *model.UserM) error
	Get(ctx context.Context, username string) (*model.UserM, error)
	Update(ctx context.Context, user *model.UserM) error
	List(ctx context.Context, offset, limit int) (int64, []*model.UserM, error)
	Delete(ctx context.Context, username string) error
}

UserStore defines the methods that need to be implemented by the user model in the store layer

Jump to

Keyboard shortcuts

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