store

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 8 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 层只需要一个版本即可。

Store 层开发规范

  • 每一个数据库表对应一个 Store 层资源,资源的CURD代码按资源分文件保存;
  • 每个 Store 层资源方法均包括标准的CURD方法和扩展方法,例如:
// PostStore 定义了 post 模块在 store 层所实现的方法.
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
}

// PostExpansion 定义了帖子操作的附加方法.
type PostExpansion interface{}
  • Store 层方法继承自 genericstore,如果需要自定义逻辑,可重新方法。

Documentation

Overview

nolint: dupl

Package store defines the storage interface for nightwatch.

nolint: dupl

Index

Constants

This section is empty.

Variables

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

ProviderSet is a Wire provider set that declares dependency injection rules. It includes the NewStore constructor function to generate datastore instances. wire.Bind is used to bind the IStore interface to the concrete implementation *datastore, allowing automatic injection of *datastore instances wherever IStore is required.

View Source
var (

	// S is a global variable for convenient access to the initialized datastore
	// instance from other packages.
	S *datastore
)

Functions

func NewStore

func NewStore(db *gorm.DB) *datastore

NewStore initializes a singleton instance of type IStore. It ensures that the datastore is only created once using sync.Once.

Types

type CronJobExpansion

type CronJobExpansion interface{}

CronJobExpansion is an empty interface provided for extending the CronJobStore interface. Developers can define cronjob-specific additional methods in this interface for future expansion.

type CronJobStore

type CronJobStore interface {
	// Create inserts a new CronJob record into the store.
	Create(ctx context.Context, obj *model.CronJobM) error

	// Update modifies an existing CronJob record in the store based on the given model.
	Update(ctx context.Context, obj *model.CronJobM) error

	// Delete removes CronJob records that satisfy the given query options.
	Delete(ctx context.Context, opts *where.Options) error

	// Get retrieves a single CronJob record that satisfies the given query options.
	Get(ctx context.Context, opts *where.Options) (*model.CronJobM, error)

	// List retrieves a list of CronJob records and their total count based on the given query options.
	List(ctx context.Context, opts *where.Options) (int64, []*model.CronJobM, error)

	// CronJobExpansion is a placeholder for extension methods for cronjobs,
	// to be implemented by additional interfaces if needed.
	CronJobExpansion
}

CronJobStore defines the interface for managing cronjob-related data operations.

type IStore

type IStore interface {
	// DB returns the *gorm.DB instance of the Store layer, which might be used in rare cases.
	DB(ctx context.Context, wheres ...where.Where) *gorm.DB
	// TX is used to implement transactions in the Biz layer.
	TX(ctx context.Context, fn func(ctx context.Context) error) error
	// CronJob returns an implementation of the CronJobStore.
	CronJob() CronJobStore
	// Job returns an implementation of the JobStore.
	Job() JobStore
}

IStore defines the methods that the Store layer needs to implement.

type JobExpansion

type JobExpansion interface{}

JobExpansion is an empty interface provided for extending the JobStore interface. Developers can define job-specific additional methods in this interface for future expansion.

type JobStore

type JobStore interface {
	// Create inserts a new Job record into the store.
	Create(ctx context.Context, obj *model.JobM) error

	// Update modifies an existing Job record in the store based on the given model.
	Update(ctx context.Context, obj *model.JobM) error

	// Delete removes Job records that satisfy the given query options.
	Delete(ctx context.Context, opts *where.Options) error

	// Get retrieves a single Job record that satisfies the given query options.
	Get(ctx context.Context, opts *where.Options) (*model.JobM, error)

	// List retrieves a list of Job records and their total count based on the given query options.
	List(ctx context.Context, opts *where.Options) (int64, []*model.JobM, error)

	// JobExpansion is a placeholder for extension methods for jobs,
	// to be implemented by additional interfaces if needed.
	JobExpansion
}

JobStore defines the interface for managing job-related data operations.

Jump to

Keyboard shortcuts

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