persistence

package
v0.0.0-...-2646333 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package persistence are implementations of the model/persisttypes interfaces

Package persistence contains components to interact with the DB

Index

Constants

View Source
const (
	//CrawlerServiceName is the name of the crawler service
	CrawlerServiceName = "crawler"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type NullPersister

type NullPersister struct{}

NullPersister is a persister that does not save any values and always returns defaults for interface methods. Handy for testing and for crawler single use scenarios. Implements the ListenerMetaDataPersister, RetrieverMetaDataRetriever, and EventsDataPersister. Acts as the 'none' configured PersisterType.

func (*NullPersister) LastBlockHash

func (n *NullPersister) LastBlockHash(eventType string, contractAddress common.Address) common.Hash

LastBlockHash returns the last block hash seen by the listener for an event type and contract address

func (*NullPersister) LastBlockNumber

func (n *NullPersister) LastBlockNumber(eventType string, contractAddress common.Address) uint64

LastBlockNumber returns the last block number seen by the listener for an event type and contract address

func (*NullPersister) RetrieveEvents

func (n *NullPersister) RetrieveEvents(criteria *model.RetrieveEventsCriteria) ([]*model.Event, error)

RetrieveEvents retrieves the Events from the persistence layer based on date in which it was received

func (*NullPersister) SaveEvents

func (n *NullPersister) SaveEvents(events []*model.Event) []error

SaveEvents stores a list of Event(s)

func (*NullPersister) UpdateLastBlockData

func (n *NullPersister) UpdateLastBlockData(events []*model.Event) error

UpdateLastBlockData should update the last block data from the Event(s)

type PersisterBlockData

type PersisterBlockData struct {
	BlockNumber uint64
	BlockHash   common.Hash
}

PersisterBlockData is the data about block stored for persistence

type PostgresPersister

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

PostgresPersister holds the DB connection and persistence

func NewPostgresPersister

func NewPostgresPersister(host string, port int, user string, password string,
	dbname string, maxConns *int, maxIdle *int, connLifetimeSecs *int) (*PostgresPersister, error)

NewPostgresPersister creates a new postgres persister

func NewPostgresPersisterFromSqlx

func NewPostgresPersisterFromSqlx(db *sqlx.DB) (*PostgresPersister, error)

NewPostgresPersisterFromSqlx creates a new postgres persister with given sqlx.DB

func (*PostgresPersister) CreateEventTable

func (p *PostgresPersister) CreateEventTable() error

CreateEventTable creates event table

func (*PostgresPersister) CreateIndices

func (p *PostgresPersister) CreateIndices() error

CreateIndices creates the indices for DB if they don't exist

func (*PostgresPersister) CreateVersionTable

func (p *PostgresPersister) CreateVersionTable(version *string) error

CreateVersionTable creates the version table and sets the version with new or existing version

func (*PostgresPersister) DropTable

func (p *PostgresPersister) DropTable(tableName string) error

DropTable drops the table with the specified tableName

func (*PostgresPersister) GetTableName

func (p *PostgresPersister) GetTableName(tableType string) string

GetTableName formats tabletype with version of this persister to return the table name

func (*PostgresPersister) LastBlockHash

func (p *PostgresPersister) LastBlockHash(eventType string, contractAddress common.Address) common.Hash

LastBlockHash returns the last block hash seen by the persister

func (*PostgresPersister) LastBlockNumber

func (p *PostgresPersister) LastBlockNumber(eventType string, contractAddress common.Address) uint64

LastBlockNumber returns the last block number seen by the persister

func (*PostgresPersister) OldVersions

func (p *PostgresPersister) OldVersions(serviceName string) ([]string, error)

OldVersions returns all versions except for the most recent one for this service

func (*PostgresPersister) PersisterVersion

func (p *PostgresPersister) PersisterVersion() (*string, error)

PersisterVersion returns and sets the latest version of this persistence

func (*PostgresPersister) PopulateBlockDataFromDB

func (p *PostgresPersister) PopulateBlockDataFromDB(tableType string) error

PopulateBlockDataFromDB will determine the block data for latest occurrence of each event type and store it into an internal map. One of the purposes of this map determines at which block to start looking for each type of event.

func (*PostgresPersister) RetrieveEvents

func (p *PostgresPersister) RetrieveEvents(criteria *model.RetrieveEventsCriteria) ([]*model.Event, error)

RetrieveEvents retrieves the Events given an offset, count, and asc/dec bool. Ordered by db id.

func (*PostgresPersister) SaveEvents

func (p *PostgresPersister) SaveEvents(events []*model.Event) []error

SaveEvents saves events to events table in DB

func (*PostgresPersister) SaveVersion

func (p *PostgresPersister) SaveVersion(versionNumber *string) error

SaveVersion saves the version for this persistence

func (*PostgresPersister) UpdateExistenceFalseForVersionTable

func (p *PostgresPersister) UpdateExistenceFalseForVersionTable(tableName string, versionNumber string,
	serviceName string) error

UpdateExistenceFalseForVersionTable updates the tableName's exists field to false in the version table

func (*PostgresPersister) UpdateLastBlockData

func (p *PostgresPersister) UpdateLastBlockData(events []*model.Event) error

UpdateLastBlockData updates the last block number seen by the persister

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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