postgres

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2019 License: AGPL-3.0 Imports: 21 Imported by: 0

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 Certificate added in v0.3.12

type Certificate struct {
	Key         string `db:"key"`
	Certificate []byte `db:"certificate"`
}

Certificate is an internal type used for persisting and reading TLS certificates from Postgres

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) Delete added in v0.3.12

func (d *DB) Delete(ctx context.Context, key string) error

Delete is our implementation of the autocert.Cache interface for deleting certificates from some underlying datastore.

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) Get added in v0.3.12

func (d *DB) Get(ctx context.Context, key string) ([]byte, error)

Get is our implementation of the method defined in the autocert.Cache interface for reading certificates from some underlying datastore.

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) Put added in v0.3.12

func (d *DB) Put(ctx context.Context, key string, data []byte) error

Put is our implementation of the method defined in the autocert.Cache interface for writing certificates to some underlying datastore.

func (*DB) ReadData added in v0.0.9

func (d *DB) ReadData(communityId string, pageSize uint64, startTime, endTime time.Time, pageCursor string) (*Page, 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(communityId 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

type Page added in v0.3.12

type Page struct {
	Events         []*Event
	NextPageCursor string
}

Page is a struct used to return a page of events. Includes a cursor which points to the next page rather than have the twirp layer do this work.

Jump to

Keyboard shortcuts

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