Documentation ¶
Overview ¶
package postgresql provides a way to connect to a postgresql database to keep track of device events.
Index ¶
- Constants
- func Metrics() []xmetrics.Metric
- type Config
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) DeleteRecord(shard int, deathDate int64, recordID int64) error
- func (c *Connection) GetBlacklist() (list []blacklist.BlackListedItem, err error)
- func (c *Connection) GetDeviceList(offset string, limit int) ([]string, error)
- func (c *Connection) GetRecords(deviceID string, limit int, stateHash string) ([]db.Record, error)
- func (c *Connection) GetRecordsOfType(deviceID string, limit int, eventType db.EventType, stateHash string) ([]db.Record, error)
- func (c *Connection) GetRecordsToDelete(shard int, limit int, deathDate int64) ([]db.RecordToDelete, error)
- func (c *Connection) GetStateHash(records []db.Record) (string, error)
- func (c *Connection) InsertRecords(records ...db.Record) error
- func (c *Connection) Ping() error
- func (c *Connection) RemoveAll() error
- type Measures
Constants ¶
const ( 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" SQLInsertedRecordsCounter = "sql_inserted_rows_count" SQLReadRecordsCounter = "sql_read_rows_count" SQLDeletedRecordsCounter = "sql_deleted_rows_count" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
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 postgresql db connection.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection manages the connection to the postgresql database, and maintains a health check on the database connection.
func CreateDbConnection ¶
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) DeleteRecord ¶
func (c *Connection) DeleteRecord(shard int, deathDate int64, recordID int64) error
DeleteRecord removes a record.
func (*Connection) GetBlacklist ¶
func (c *Connection) GetBlacklist() (list []blacklist.BlackListedItem, err error)
GetBlacklist returns a list of blacklisted devices.
func (*Connection) GetDeviceList ¶
func (c *Connection) GetDeviceList(offset string, limit int) ([]string, error)
GetDeviceList returns a list of device ids where the device id is greater than the offset device id.
func (*Connection) GetRecords ¶
GetRecords returns a list of records for a given device.
func (*Connection) GetRecordsOfType ¶
func (c *Connection) GetRecordsOfType(deviceID string, limit int, eventType db.EventType, stateHash string) ([]db.Record, error)
GetRecords returns a list of records for a given device and event type.
func (*Connection) GetRecordsToDelete ¶
func (c *Connection) GetRecordsToDelete(shard int, limit int, deathDate int64) ([]db.RecordToDelete, error)
GetRecordsToDelete returns a list of record ids and deathdates not past a given date.
func (*Connection) GetStateHash ¶ added in v0.5.0
func (c *Connection) GetStateHash(records []db.Record) (string, error)
GetStateHash returns a hash for the latest record added to the database
func (*Connection) InsertRecords ¶
func (c *Connection) InsertRecords(records ...db.Record) error
InsertEvent adds a list of records to the table.
func (*Connection) Ping ¶
func (c *Connection) Ping() error
Ping is for pinging the database to verify that the connection is still good.
func (*Connection) RemoveAll ¶
func (c *Connection) RemoveAll() error
RemoveAll removes everything in the events table. Used for testing.
type Measures ¶
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 SQLInsertedRecords metrics.Counter SQLReadRecords metrics.Counter SQLDeletedRecords metrics.Counter }