db

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStateNotSynchronized indicates the state database may be empty
	ErrStateNotSynchronized = errors.New("state not synchronized")
)

Functions

func InitContext added in v0.0.4

func InitContext(ctx context.Context, cfg Config) (*sqlx.DB, error)

InitContext initializes DB connection by the given config

func RunMigrationsUp

func RunMigrationsUp(pg *sqlx.DB) error

RunMigrationsUp runs migrate-up for the given config.

Types

type Config

type Config struct {
	// Database name
	Name string `mapstructure:"Name"`

	// Database User name
	User string `mapstructure:"User"`

	// Database Password of the user
	Password string `mapstructure:"Password"`

	// Host address of database
	Host string `mapstructure:"Host"`

	// Port Number of database
	Port string `mapstructure:"Port"`

	// EnableLog
	// DEPRECATED
	EnableLog bool `mapstructure:"EnableLog"`

	// MaxConns is the maximum number of connections in the pool.
	MaxConns int `mapstructure:"MaxConns"`
}

Config provide fields to configure the pool

type DB

type DB interface {
	StoreLastProcessedBlock(ctx context.Context, block uint64, task string) error
	GetLastProcessedBlock(ctx context.Context, task string) (uint64, error)

	StoreMissingBatchKeys(ctx context.Context, bks []types.BatchKey) error
	GetMissingBatchKeys(ctx context.Context, limit uint) ([]types.BatchKey, error)
	DeleteMissingBatchKeys(ctx context.Context, bks []types.BatchKey) error

	GetOffChainData(ctx context.Context, key common.Hash) (*types.OffChainData, error)
	ListOffChainData(ctx context.Context, keys []common.Hash) ([]types.OffChainData, error)
	StoreOffChainData(ctx context.Context, od []types.OffChainData) error
	CountOffchainData(ctx context.Context) (uint64, error)
}

DB defines functions that a DB instance should implement

func New

func New(ctx context.Context, pg *sqlx.DB) (DB, error)

New instantiates a DB

Jump to

Keyboard shortcuts

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