db

package
v0.0.1-test Latest Latest
Warning

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

Go to latest
Published: Feb 19, 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 {
	BeginStateTransaction(ctx context.Context) (Tx, error)
	Exists(ctx context.Context, key common.Hash) bool
	GetLastProcessedBlock(ctx context.Context, task string) (uint64, error)
	GetOffChainData(ctx context.Context, key common.Hash, dbTx sqlx.QueryerContext) (types.ArgBytes, error)
	StoreLastProcessedBlock(ctx context.Context, task string, block uint64, dbTx sqlx.ExecerContext) error
	StoreOffChainData(ctx context.Context, od []types.OffChainData, dbTx sqlx.ExecerContext) error
}

DB defines functions that a DB instance should implement

func New

func New(pg *sqlx.DB) DB

New instantiates a DB

type Tx added in v0.0.4

type Tx interface {
	sqlx.ExecerContext
	sqlx.QueryerContext
	driver.Tx
}

Tx is the interface that defines functions a db tx has to implement

Jump to

Keyboard shortcuts

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