db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = uint(2)

SchemaVersion is the current version of the DB schema. N.B.: this constant should be updated every time new migrations are added.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the requested user is not found.

Functions

This section is empty.

Types

type Config

type Config struct {
	RawURI string

	MigrationsDir string
	SchemaVersion uint
	// contains filtered or unexported fields
}

Config encapsulates the input required to configure a database connection.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags maps the provided CLI arguments to fields in this configuration object.

func (Config) URI

func (cfg Config) URI() (string, error)

URI parses this configuration object's database URI, reads the database password from the specified file, and injects it in the URI it returns.

type DB

type DB interface {
	// Ping ensures this database client can reach the database.
	Ping(ctx context.Context) error
	// CreateUser stores the provided user.
	CreateUser(ctx context.Context, user *domain.User) (int, error)
	// ReadUsers returns all stored users.
	ReadUsers(ctx context.Context) ([]*domain.User, error)
	// ReadUserByID return the stored user corresponding to the provided ID.
	ReadUserByID(ctx context.Context, id int) (*domain.User, error)
	// Close closes this connection to the database.
	Close() error
}

DB is the interface for a database client.

type PostgreSQLDB

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

PostgreSQLDB is a PostgreSQL-compatible implementation of DB.

func NewPostgreSQLDB

func NewPostgreSQLDB(config *Config) (*PostgreSQLDB, error)

NewPostgreSQLDB creates a new connection to the configured PostgreSQL DB.

func (*PostgreSQLDB) Close

func (db *PostgreSQLDB) Close() error

Close closes this connection to the database.

func (PostgreSQLDB) CreateUser

func (db PostgreSQLDB) CreateUser(ctx context.Context, user *domain.User) (int, error)

CreateUser stores the provided user.

func (PostgreSQLDB) Ping

func (db PostgreSQLDB) Ping(ctx context.Context) error

Ping ensures this database client can reach the database.

func (PostgreSQLDB) ReadUserByID

func (db PostgreSQLDB) ReadUserByID(ctx context.Context, userID int) (*domain.User, error)

ReadUserByID return the stored user corresponding to the provided ID.

func (PostgreSQLDB) ReadUsers

func (db PostgreSQLDB) ReadUsers(ctx context.Context) ([]*domain.User, error)

ReadUsers returns all stored users.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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