Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type DB
- type PostgreSQLDB
- func (db *PostgreSQLDB) Close() error
- func (db PostgreSQLDB) CreateUser(ctx context.Context, user *domain.User) (int, error)
- func (db PostgreSQLDB) Ping(ctx context.Context) error
- func (db PostgreSQLDB) ReadUserByID(ctx context.Context, userID int) (*domain.User, error)
- func (db PostgreSQLDB) ReadUsers(ctx context.Context) ([]*domain.User, error)
Constants ¶
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 ¶
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 ¶
RegisterFlags maps the provided CLI arguments to fields in this configuration object.
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 ¶
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 ¶
ReadUserByID return the stored user corresponding to the provided ID.