store

package
v0.2.0-alpha.14 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 8 Imported by: 0

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 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 ChainExpansion

type ChainExpansion interface{}

ChainExpansion is an empty interface provided for extending the ChainStore interface. Developers can define chain-specific additional methods in this interface for future expansion.

type ChainStore

type ChainStore interface {
	// Create inserts a new Chain record into the store.
	Create(ctx context.Context, obj *model.ChainM) error

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

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

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

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

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

ChainStore defines the interface for managing chain-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
	// Chain returns an implementation of the ChainStore.
	Chain() ChainStore
	// MinerSet returns an implementation of the MinerSetStore.
	MinerSet() MinerSetStore
	// Miner returns an implementation of the MinerStore.
	Miner() MinerStore
}

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

type MinerExpansion

type MinerExpansion interface{}

MinerExpansion is an empty interface provided for extending the MinerStore interface. Developers can define miner-specific additional methods in this interface for future expansion.

type MinerSetExpansion

type MinerSetExpansion interface{}

MinerSetExpansion is an empty interface provided for extending the MinerSetStore interface. Developers can define minerset-specific additional methods in this interface for future expansion.

type MinerSetStore

type MinerSetStore interface {
	// Create inserts a new MinerSet record into the store.
	Create(ctx context.Context, obj *model.MinerSetM) error

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

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

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

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

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

MinerSetStore defines the interface for managing minerset-related data operations.

type MinerStore

type MinerStore interface {
	// Create inserts a new Miner record into the store.
	Create(ctx context.Context, obj *model.MinerM) error

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

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

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

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

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

MinerStore defines the interface for managing miner-related data operations.

Jump to

Keyboard shortcuts

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