postgres

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2018 License: AGPL-3.0 Imports: 19 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateDown

func MigrateDown(db *sql.DB, steps int, logger kitlog.Logger) error

MigrateDown attempts to run down migrations against Postgres. It takes as parameters an sql.DB instance, the number of steps to run, and a logger instance. Migrations are loaded from a bindata generated module that is compiled into the binary.

func MigrateDownAll

func MigrateDownAll(db *sql.DB, logger kitlog.Logger) error

MigrateDownAll attempts to run all down migrations against Postgres. It takes as parameters an sql.DB instance, and a logger instance. Migrations are loaded from a bindata generated module that is compiled into the binary.

func MigrateUp

func MigrateUp(db *sql.DB, logger kitlog.Logger) error

MigrateUp attempts to run all up migrations against Postgres. Migrations are loaded from a bindata generated module that is compiled into the binary. It takes as parameters an sql.DB instance, and a logger instance.

func NewMigration

func NewMigration(dirName, migrationName string, logger kitlog.Logger) error

NewMigration creates a new pair of files into which an SQL migration should be written. All this is doing is ensuring files created are correctly named.

func Open

func Open(connStr string) (*sqlx.DB, error)

Open takes as input a connection string for a DB, and returns either a sqlx.DB instance or an error.

Types

type Cursor added in v0.0.9

type Cursor struct {
	EventID   int64     `json:"eventID"`
	Timestamp time.Time `json:"timestamp"`
}

Cursor is an internal type used for serializing or parsing page cursors.

type DB added in v0.0.9

type DB struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

DB is a struct that wraps an sqlx.DB instance that exposes some methods to read and write data.

func NewDB added in v0.0.9

func NewDB(connStr string, verbose bool, logger kitlog.Logger) *DB

NewDB is a constructor that returns a new DB instance for the given configuration. We pass in a connection string for the database, and in addition we can pass in a verbose flag which causes the binary to output more verbose log information.

func (*DB) DeleteData added in v0.0.9

func (d *DB) DeleteData(before time.Time, execute bool) error

DeleteData takes as input a timestamp, and after it is executed will have deleted all events in the database from before the submitted time interval for any policy. This function also takes a `execute` parameter. If set to true the delete operation is performed and committed, but if set to false it is executed without committing the transaction. This allows a caller to see how many events would be deleted.

func (*DB) Ping added in v0.1.1

func (d *DB) Ping() error

Ping attempts to verify a connection to the database is still alive, establishing a connection if necessary by executing a simple select query agianst the DB. Note using DB.Ping() did not work as expected as if there are existing connections in the pool that aren't used it will return no error without actually going to the DB to check.

func (*DB) ReadData added in v0.0.9

func (d *DB) ReadData(policyId string, pageSize uint64, startTime, endTime time.Time, pageCursor string) ([]*Event, error)

ReadData returns a list of Event types for the given query parameters.

func (*DB) Start added in v0.0.9

func (d *DB) Start() error

Start connects to the database, and runs any pending up migrations.

func (*DB) Stop added in v0.0.9

func (d *DB) Stop() error

Stop terminates the DB connection, closing the pool of connections.

func (*DB) WriteData added in v0.0.9

func (d *DB) WriteData(policyId string, data []byte, deviceToken string) error

WriteData is the function that is responsible for writing data to the actual database. Takes as input the id of the policy the policy for which we are storing data and a byte slice containing the encrypted data to be persisted. In addition we also pass in the unique device token.

type Event added in v0.0.9

type Event struct {
	ID         int64     `db:"id"`
	RecordedAt time.Time `db:"recorded_at"`
	Data       []byte    `db:"data"`
}

Event is a type used to read encrypted events back from the database

Jump to

Keyboard shortcuts

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