store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("record not found")
)

Functions

This section is empty.

Types

type ActivityPeriodRow

type ActivityPeriodRow struct {
	Period int64
	Min    types.Time
	Max    types.Time
}

type BlockSeqStore

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

BlockSeqStore handles operations on blocks

func NewBlockSeqStore

func NewBlockSeqStore(db *gorm.DB) *BlockSeqStore

func (BlockSeqStore) Create

func (s BlockSeqStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (BlockSeqStore) CreateIfNotExists

func (s BlockSeqStore) CreateIfNotExists(block *model.BlockSeq) error

CreateIfNotExists creates the block if it does not exist

func (BlockSeqStore) DeleteByHeight

func (s BlockSeqStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (*BlockSeqStore) DeleteOlderThan

func (s *BlockSeqStore) DeleteOlderThan(purgeThreshold time.Time, activityPeriods []ActivityPeriodRow) (*int64, error)

DeleteOlderThan deletes block sequence older than given threshold

func (BlockSeqStore) FindBy

func (s BlockSeqStore) FindBy(key string, value interface{}) (*model.BlockSeq, error)

FindBy returns a block for a matching attribute

func (BlockSeqStore) FindByHeight

func (s BlockSeqStore) FindByHeight(height int64) (*model.BlockSeq, error)

FindByHeight returns a block with the matching height

func (BlockSeqStore) FindByID

func (s BlockSeqStore) FindByID(id int64) (*model.BlockSeq, error)

FindByID returns a block with matching ID

func (*BlockSeqStore) FindMostRecent

func (s *BlockSeqStore) FindMostRecent() (*model.BlockSeq, error)

FindMostRecent finds most recent block sequence

func (*BlockSeqStore) GetAvgRecentTimes

func (s *BlockSeqStore) GetAvgRecentTimes(limit int64) GetAvgRecentTimesResult

GetAvgRecentTimes Gets average block times for recent blocks by limit

func (BlockSeqStore) Save

func (s BlockSeqStore) Save(record interface{}) error

Save saves record to database

func (*BlockSeqStore) Summarize

func (s *BlockSeqStore) Summarize(interval types.SummaryInterval, activityPeriods []ActivityPeriodRow) ([]BlockSeqSummary, error)

Summarize gets the summarized version of block sequences

func (BlockSeqStore) Truncate

func (s BlockSeqStore) Truncate() error

Truncate removes all records from the table

func (BlockSeqStore) Update

func (s BlockSeqStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type BlockSeqSummary

type BlockSeqSummary struct {
	TimeBucket   types.Time `json:"time_bucket"`
	Count        int64      `json:"count"`
	BlockTimeAvg float64    `json:"block_time_avg"`
}

type BlockSummaryStore

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

BlockSummaryStore handles operations on block summary

func NewBlockSummaryStore

func NewBlockSummaryStore(db *gorm.DB) *BlockSummaryStore

func (BlockSummaryStore) Create

func (s BlockSummaryStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (BlockSummaryStore) DeleteByHeight

func (s BlockSummaryStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (*BlockSummaryStore) DeleteOlderThan

func (s *BlockSummaryStore) DeleteOlderThan(interval types.SummaryInterval, purgeThreshold time.Time) (*int64, error)

DeleteOlderThan deletes block summary records older than given threshold

func (BlockSummaryStore) Find

Find find block summary by query

func (*BlockSummaryStore) FindActivityPeriods

func (s *BlockSummaryStore) FindActivityPeriods(interval types.SummaryInterval, indexVersion int64) ([]ActivityPeriodRow, error)

FindActivityPeriods Finds activity periods

func (*BlockSummaryStore) FindMostRecent

func (s *BlockSummaryStore) FindMostRecent() (*model.BlockSummary, error)

FindMostRecent finds most recent block summary

func (*BlockSummaryStore) FindMostRecentByInterval

func (s *BlockSummaryStore) FindMostRecentByInterval(interval types.SummaryInterval) (*model.BlockSummary, error)

FindMostRecentByInterval finds most recent block summary for given time interval

func (*BlockSummaryStore) FindSummary

func (s *BlockSummaryStore) FindSummary(interval types.SummaryInterval, period string) ([]model.BlockSummary, error)

FindSummary Gets summary of block sequences

func (BlockSummaryStore) Save

func (s BlockSummaryStore) Save(record interface{}) error

Save saves record to database

func (BlockSummaryStore) Truncate

func (s BlockSummaryStore) Truncate() error

Truncate removes all records from the table

func (BlockSummaryStore) Update

func (s BlockSummaryStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type DatabaseStore

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

DatabaseStore handles operations on blocks

func NewDatabaseStore

func NewDatabaseStore(db *gorm.DB) *DatabaseStore

func (*DatabaseStore) GetTotalSize

func (s *DatabaseStore) GetTotalSize() (*GetTotalSizeResult, error)

FindSummary Gets average block times for interval

type GetAvgRecentTimesResult

type GetAvgRecentTimesResult struct {
	StartHeight int64   `json:"start_height"`
	EndHeight   int64   `json:"end_height"`
	StartTime   string  `json:"start_time"`
	EndTime     string  `json:"end_time"`
	Count       int64   `json:"count"`
	Diff        float64 `json:"diff"`
	Avg         float64 `json:"avg"`
}

GetAvgRecentTimesResult Contains results for GetAvgRecentTimes query

type GetAvgTimesForIntervalRow

type GetAvgTimesForIntervalRow struct {
	TimeInterval string  `json:"time_interval"`
	Count        int64   `json:"count"`
	Avg          float64 `json:"avg"`
}

GetAvgTimesForIntervalRow Contains row of data for FindSummary query

type GetTotalSizeResult

type GetTotalSizeResult struct {
	Size float64 `json:"size"`
}

GetAvgTimesForIntervalRow Contains row of data for FindSummary query

type ReportsStore

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

ReportsStore handles operations on reports

func NewReportsStore

func NewReportsStore(db *gorm.DB) *ReportsStore

func (ReportsStore) Create

func (s ReportsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (ReportsStore) DeleteByHeight

func (s ReportsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (*ReportsStore) DeleteReindexing

func (s *ReportsStore) DeleteReindexing() error

DeleteReindexing deletes reports with kind reindexing sequential or parallel

func (ReportsStore) FindNotCompletedByIndexVersion

func (s ReportsStore) FindNotCompletedByIndexVersion(indexVersion int64, kinds ...model.ReportKind) (*model.Report, error)

FindNotCompletedByIndexVersion returns the report by index version and kind

func (ReportsStore) FindNotCompletedByKind

func (s ReportsStore) FindNotCompletedByKind(kinds ...model.ReportKind) (*model.Report, error)

Last returns the last report

func (ReportsStore) Last

func (s ReportsStore) Last() (*model.Report, error)

Last returns the last report

func (ReportsStore) Save

func (s ReportsStore) Save(record interface{}) error

Save saves record to database

func (ReportsStore) Truncate

func (s ReportsStore) Truncate() error

Truncate removes all records from the table

func (ReportsStore) Update

func (s ReportsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type Store

type Store struct {
	Database  *DatabaseStore
	Syncables *SyncablesStore
	Reports   *ReportsStore

	BlockSeq *BlockSeqStore

	BlockSummary *BlockSummaryStore
	// contains filtered or unexported fields
}

Store handles all database operations

func New

func New(connStr string) (*Store, error)

NewIndexerMetric returns a new store from the connection string

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection

func (*Store) SetDebugMode

func (s *Store) SetDebugMode(enabled bool)

SetDebugMode enabled detailed query logging

func (*Store) Test

func (s *Store) Test() error

Test checks the connection status

type SyncablesStore

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

SyncablesStore handles operations on syncables

func NewSyncablesStore

func NewSyncablesStore(db *gorm.DB) *SyncablesStore

func (SyncablesStore) Create

func (s SyncablesStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (SyncablesStore) CreateOrUpdate

func (s SyncablesStore) CreateOrUpdate(val *model.Syncable) error

CreateOrUpdate creates a new syncable or updates an existing one

func (SyncablesStore) DeleteByHeight

func (s SyncablesStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (SyncablesStore) FindByHeight

func (s SyncablesStore) FindByHeight(height int64) (syncable *model.Syncable, err error)

Exists returns true if a syncable exists at give height

func (SyncablesStore) FindFirstByDifferentIndexVersion

func (s SyncablesStore) FindFirstByDifferentIndexVersion(indexVersion int64) (*model.Syncable, error)

FindFirstByDifferentIndexVersion returns first syncable with different index version

func (SyncablesStore) FindMostRecent

func (s SyncablesStore) FindMostRecent() (*model.Syncable, error)

FindMostRecent returns the most recent syncable

func (SyncablesStore) FindMostRecentByDifferentIndexVersion

func (s SyncablesStore) FindMostRecentByDifferentIndexVersion(indexVersion int64) (*model.Syncable, error)

FindMostRecentByDifferentIndexVersion returns the most recent syncable with different index version

func (SyncablesStore) Save

func (s SyncablesStore) Save(record interface{}) error

Save saves record to database

func (SyncablesStore) SetProcessedAtForRange

func (s SyncablesStore) SetProcessedAtForRange(reportID types.ID, startHeight int64, endHeight int64) error

CreateOrUpdate creates a new syncable or updates an existing one

func (SyncablesStore) Truncate

func (s SyncablesStore) Truncate() error

Truncate removes all records from the table

func (SyncablesStore) Update

func (s SyncablesStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

Jump to

Keyboard shortcuts

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