storage

package
v0.0.0-...-0f47a2f Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectionString

func ConnectionString(port uint16, host, user, password, dbname string) string

ConnectionString returns on the connection string format supported by postgres. https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING

func UseLogger

func UseLogger(sLogger btclog.Logger)

UseLogger sets the subsystem logs to use the provided loggers.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB defines the parameters needed to use a persistence db instance connect to.

func NewDB

func NewDB(ctx context.Context, connInfo string) (*DB, error)

NewDB returns an opened db instance whose connection has been tested with ping request. It generates the required tables if they don't exist.

func (*DB) CleanUpLocalData

func (d *DB) CleanUpLocalData(lastSyncedBlock uint64)

CleanUpLocalData removes any dirty writes that may have been written on a certain last synced block.

func (*DB) QueryLocalData

func (d *DB) QueryLocalData(method utils.Method, r Reader, sender string,
	params ...interface{},
) ([]interface{}, error)

QueryLocalData executes the sql statement associated with the provided local method and uses the reader interface provided to read the row data result set. It then returns an array of data for each row read successfully otherwise an error is returned.

func (*DB) SetLocalData

func (d *DB) SetLocalData(method utils.Method, params ...interface{}) error

SetLocalData inserts the provided data using the sql staements associated with method param provided.

type Reader

type Reader interface {
	Read(fn func(fields ...any) error) (interface{}, error)
}

Reader defines the method that reads the row fields into the require data interface. To read data, pass pointers to the expect field the parameter function.

Jump to

Keyboard shortcuts

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