database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *pgxpool.Pool
)

Functions

func AddNextBlockNumberForProcessing

func AddNextBlockNumberForProcessing(tx pgx.Tx, blockNumber int64, forward bool, checkPrevBlock bool) (err error)

func AdditionalDataTableName

func AdditionalDataTableName(dataTablePostfix string) string

func BeginTransaction

func BeginTransaction() (tx *pgx.Tx, err error)

func BlockConnectingStateTableName

func BlockConnectingStateTableName() string

func BlockIsAlreadyProcessed

func BlockIsAlreadyProcessed(tx pgx.Tx, hash string) (processed bool, err error)

BlockIsAlreadyProcessed returns `true` if block with such hash has been marked as processed earlier. Otherwise (including error cases) returns `false`.

func BlocksForProcessingTableName

func BlocksForProcessingTableName() string

func Commit

func Commit(tx pgx.Tx) (err error)

func DataTableName

func DataTableName() string

func DeleteOutdatedConnectingStateRecords

func DeleteOutdatedConnectingStateRecords(tx pgx.Tx, blockNumber int64) (err error)

func EnsureSchema

func EnsureSchema() (err error)

EnsureSchema executes provided schema definition SQL file. By default it ensures all required tables / indexes / constraints / triggers are present. In case if some table (or index, or ...) is absent - it would be recreated. Does not replaces tables in cae if them are present (to not to drop data occasionally).

func Exec

func Exec(tx pgx.Tx, sql string) (tag pgconn.CommandTag, err error)

func ExecTxFree

func ExecTxFree(sql string) (tag pgconn.CommandTag, err error)

func Free

func Free()

func GetBlockConnectingState

func GetBlockConnectingState(tx pgx.Tx, blockNumber int64) (state uint8, err error)

func GetNextBlockNumberForProcessing

func GetNextBlockNumberForProcessing(tx pgx.Tx, impl core.IndexImplementation) (blockNumber int64, forward bool, checkPrevBlock bool, err error)

GetNextBlockNumberForProcessing returns block number, that is stored in the database as next to be processed. `tx` defines the postgres's transaction into which the data should be fetched. `impl` is used for the cases when blocks processing should begin in a non-standard manner (e.g. not from zero index).

func GetPrevBlockNumber

func GetPrevBlockNumber(tx pgx.Tx, blockNumber int64) (prevBlockNumber int64, err error)

func IncrementIndexOffset

func IncrementIndexOffset(tx pgx.Tx) (currentOffset int64, err error)

IncrementIndexOffset increments block offset of the index in database, using the same TX context, as the rest of index mechanics. Returns current offset of the index, that is fetched in the same query, to save one round trip to the database.

func IndexNamePrefix

func IndexNamePrefix() string

func Init

func Init() (err error)

func InitIndexBlockOffset

func InitIndexBlockOffset() (currentOffset int64, err error)

InitIndexBlockOffset tries to initialize index's block offset number before usage. In case if this index already has the offset number - no error would be emitted (muted on database level). Returns current offset that has been last stored.

func InsertBlockConnectingInfo

func InsertBlockConnectingInfo(tx pgx.Tx, blockNumber, prevBlockNumber int64, state uint8) (err error)

func MarkBlockProcessed

func MarkBlockProcessed(tx pgx.Tx, hash string) (err error)

MarkBlockProcessed adds latest_blocks hash to the processed latest_blocks table. Returns error if this block is already processed.

func MinimizeSQLScript

func MinimizeSQLScript(query string) string

func ProcessedBlocksTableName

func ProcessedBlocksTableName() string

func Query

func Query(tx pgx.Tx, sql string) (rows pgx.Rows, err error)

func QueryTxFree

func QueryTxFree(sql string, args ...interface{}) (rows pgx.Rows, err error)

func RemoveNextBlockNumberForProcessing

func RemoveNextBlockNumberForProcessing(tx pgx.Tx, blockNumber int64, forward bool) (err error)

func Rollback

func Rollback(tx pgx.Tx) (err error)

func UpdateBlockConnectingState

func UpdateBlockConnectingState(tx pgx.Tx, blockNumber int64, newState uint8) (err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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