db

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2019 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RetryCounter                = "retry_count"
	PoolOpenConnectionsGauge    = "pool_open_connections"
	PoolInUseConnectionsGauge   = "pool_in_use_connections"
	PoolIdleConnectionsGauge    = "pool_idle_connections"
	SQLWaitCounter              = "sql_wait_count"
	SQLWaitDurationCounter      = "sql_wait_duration_seconds"
	SQLMaxIdleClosedCounter     = "sql_max_idle_closed"
	SQLMaxLifetimeClosedCounter = "sql_max_lifetime_closed"
	SQLQuerySuccessCounter      = "sql_query_success_count"
	SQLQueryFailureCounter      = "sql_query_failure_count"
	SQLQueryRetryCounter        = "sql_query_retry_count"
	SQLDeletedRowsCounter       = "sql_deleted_rows_count"
)

Variables

This section is empty.

Functions

func Metrics added in v0.2.0

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

Types

type Config added in v0.2.0

type Config struct {
	Server         string
	Username       string
	Database       string
	SSLRootCert    string
	SSLKey         string
	SSLCert        string
	NumRetries     int
	PruneLimit     int
	WaitTimeMult   time.Duration
	ConnectTimeout time.Duration
	OpTimeout      time.Duration

	// MaxIdleConns sets the max idle connections, the min value is 2
	MaxIdleConns int

	// MaxOpenConns sets the max open connections, to specify unlimited set to 0
	MaxOpenConns int

	PingInterval time.Duration
}

Config contains the initial configuration information needed to create a db connection.

type Connection added in v0.1.1

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

Connection contains the tools to edit the database.

func CreateDbConnection added in v0.2.0

func CreateDbConnection(config Config, provider provider.Provider, health *health.Health) (*Connection, error)

CreateDbConnection creates db connection and returns the struct to the consumer.

func (*Connection) Close added in v0.2.0

func (db *Connection) Close() error

func (*Connection) GetBlacklist added in v0.3.1

func (db *Connection) GetBlacklist() (list []blacklist.BlackListedItem, err error)

GetBlacklist returns a list of blacklisted devices

func (*Connection) GetRecords added in v0.2.0

func (db *Connection) GetRecords(deviceID string, limit int) ([]Record, error)

GetRecords returns a list of records for a given device

func (*Connection) GetRecordsOfType added in v0.2.0

func (db *Connection) GetRecordsOfType(deviceID string, limit int, eventType EventType) ([]Record, error)

GetRecords returns a list of records for a given device

func (*Connection) InsertRecords added in v0.2.1

func (db *Connection) InsertRecords(records ...Record) error

InsertEvent adds a record to the table.

func (*Connection) Ping added in v0.2.0

func (db *Connection) Ping() error

func (*Connection) PruneRecords added in v0.2.0

func (db *Connection) PruneRecords(t int64) error

PruneRecords removes records past their deathdate.

func (*Connection) RemoveAll added in v0.1.1

func (db *Connection) RemoveAll() error

RemoveAll removes everything in the events table. Used for testing.

type EventType added in v0.3.2

type EventType int
const (
	// default event type
	Default EventType = iota

	// event type for online and offline events
	State
)

func ParseEventType added in v0.3.2

func ParseEventType(event string) EventType

func (EventType) String added in v0.3.2

func (i EventType) String() string

type Inserter added in v0.2.0

type Inserter interface {
	InsertRecords(records ...Record) error
}

type Measures added in v0.2.0

type Measures struct {
	Retry                xmetrics.Incrementer
	PoolOpenConnections  metrics.Gauge
	PoolInUseConnections metrics.Gauge
	PoolIdleConnections  metrics.Gauge

	SQLWaitCount         metrics.Counter
	SQLWaitDuration      metrics.Counter
	SQLMaxIdleClosed     metrics.Counter
	SQLMaxLifetimeClosed metrics.Counter
	SQLQuerySuccessCount metrics.Counter
	SQLQueryFailureCount metrics.Counter
	SQLQueryRetryCount   metrics.Counter
	SQLDeletedRows       metrics.Counter
}

func NewMeasures added in v0.2.0

func NewMeasures(p provider.Provider) Measures

type Option added in v0.4.2

type Option func(r *retryConfig)

func WithInterval added in v0.4.2

func WithInterval(interval time.Duration) Option

func WithMeasures added in v0.4.2

func WithMeasures(p provider.Provider) Option

func WithRetries added in v0.4.2

func WithRetries(retries int) Option

func WithSleep added in v0.4.2

func WithSleep(sleep func(time.Duration)) Option

type Pruner added in v0.2.0

type Pruner interface {
	PruneRecords(t int64) error
}

type Record added in v0.2.0

type Record struct {
	ID        int       `json:"id"`
	Type      EventType `json:"type" gorm:"type:int"`
	DeviceID  string    `json:"deviceid"`
	BirthDate int64     `json:"birthdate"`
	DeathDate int64     `json:"deathdate"`
	Data      []byte    `json:"data"`
	Nonce     []byte    `json:"nonce"`
	Alg       string    `json:"alg"`
	KID       string    `json:"kid" gorm:"Column:kid"`
}

func (Record) TableName added in v0.2.0

func (Record) TableName() string

set Record's table name to be `events`

type RecordGetter added in v0.2.0

type RecordGetter interface {
	GetRecords(deviceID string, limit int) ([]Record, error)
	GetRecordsOfType(deviceID string, limit int, eventType EventType) ([]Record, error)
}

type RetryInsertService added in v0.2.0

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

func CreateRetryInsertService added in v0.2.0

func CreateRetryInsertService(inserter Inserter, options ...Option) RetryInsertService

func (RetryInsertService) InsertRecords added in v0.2.1

func (ri RetryInsertService) InsertRecords(records ...Record) error

type RetryListGService added in v0.3.1

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

func CreateRetryListGService added in v0.3.1

func CreateRetryListGService(listGetter blacklist.Updater, options ...Option) RetryListGService

func (RetryListGService) GetBlacklist added in v0.3.1

func (ltg RetryListGService) GetBlacklist() (list []blacklist.BlackListedItem, err error)

type RetryRGService added in v0.2.0

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

func CreateRetryRGService added in v0.2.0

func CreateRetryRGService(recordGetter RecordGetter, options ...Option) RetryRGService

func (RetryRGService) GetRecords added in v0.2.0

func (rtg RetryRGService) GetRecords(deviceID string, limit int) ([]Record, error)

func (RetryRGService) GetRecordsOfType added in v0.2.0

func (rtg RetryRGService) GetRecordsOfType(deviceID string, limit int, eventType EventType) ([]Record, error)

type RetryUpdateService added in v0.2.0

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

func CreateRetryUpdateService added in v0.2.0

func CreateRetryUpdateService(pruner Pruner, options ...Option) RetryUpdateService

func (RetryUpdateService) PruneRecords added in v0.2.0

func (ru RetryUpdateService) PruneRecords(t int64) error

Jump to

Keyboard shortcuts

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