db

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RollbackError = errors.New("rollback this tx")

Functions

func Connect

func Connect(databaseURL string) (*sqlx.DB, func(), error)

Connect connects to the database

func DB

func DB() *sqlx.DB

DB exposes db instance to the outer world

func Init

func Init(databaseURL string) error

Init will initalize global connection

func TestDBURL

func TestDBURL() string

TestDBURL returns database URL string based on the environment variables

func WithTransaction

func WithTransaction(f func(*sqlx.Tx) error) error

WithTransaction runs given function in a transaction

Types

type ScanAggr

type ScanAggr struct {
	Host            string `db:"host" json:"host"`
	NumberOfSamples int    `db:"number_of_samples" json:"number_of_samples"`
	Up              bool   `db:"up" json:"up"`
}

ScanAggr represents struct for scan aggregations over some interval

type ScanAggrStore

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

ScanAggrStore is a struct ot access agggeration related db stuff

func NewDefaultScanAggrStore

func NewDefaultScanAggrStore() *ScanAggrStore

NewDefaultScanAggrStore creates new store using default db connection

func NewScanAggrStore

func NewScanAggrStore(dbh dbHandler) *ScanAggrStore

NewScanAggrStore creates new store using given db handler

func (*ScanAggrStore) AllScanAggregationsFor

func (store *ScanAggrStore) AllScanAggregationsFor(interval time.Duration) ([]ScanAggr, error)

AllScanAggregationsFor returns scan agggerations for last interval

type ScanResult

type ScanResult struct {
	ResultID  int       `db:"scan_result_id"`
	ScanIP    string    `db:"scan_ip"`
	Host      string    `db:"host"`
	Plaftorm  string    `db:"platform"`
	Up        bool      `db:"up"`
	CreatedAt time.Time `db:"created_at"`
	QueryData []byte    `db:"query_data"`
}

ScanResult represent record in a table

type ScanResultStore

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

ScanResultStore is a struct ot access scan results from db

func NewDefaultScanResultStore

func NewDefaultScanResultStore() *ScanResultStore

NewDefaultScanResultStore creates new store using default db connection

func NewScanResultStore

func NewScanResultStore(dbh dbHandler) *ScanResultStore

NewScanResultStore creates new store using given db handler

func (*ScanResultStore) AllScanResults

func (store *ScanResultStore) AllScanResults() ([]*ScanResult, error)

AllScanResults returns all scan_results from db

func (*ScanResultStore) DeleteResultsOlderThan

func (store *ScanResultStore) DeleteResultsOlderThan(age time.Duration) error

DeleteResultsOlderThan will delete all results older than given age

func (*ScanResultStore) SaveScanResult

func (store *ScanResultStore) SaveScanResult(sr *ScanResult) error

SaveScanResult saves one given scan result

func (*ScanResultStore) SelectScanResults

func (store *ScanResultStore) SelectScanResults(query string) ([]*ScanResult, error)

SelectScanResults selects scan results based on query

Jump to

Keyboard shortcuts

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