db

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypePostgres holder for postgres database
	TypePostgres string = "POSTGRES"
)

Variables

This section is empty.

Functions

func NewErrAlreadyExists

func NewErrAlreadyExists(msg string) error

NewErrAlreadyExists wraps a message in an ErrAlreadyExists object.

Types

type Common

type Common interface {
	// Close closes the db connections
	Close(ctx context.Context) Error
	// Create stores the object
	Create(ctx context.Context, i any) Error
	// DoMigration runs database migrations
	DoMigration(ctx context.Context) Error
	// LoadTestData adds test data to the database
	LoadTestData(ctx context.Context) Error
}

Common wraps common database functions

type DB

type DB interface {
	Common
	User
}

DB represents a database client

type ErrAlreadyExists

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

ErrAlreadyExists is returned when a caller tries to insert a database entry that already exists in the db.

func (*ErrAlreadyExists) Error

func (e *ErrAlreadyExists) Error() string

Error returns the error message as a string.

type Error

type Error error

Error represents a database specific error

var (
	// ErrGenID is returned when creating a new ID can't be generated for a new model.
	ErrGenID Error = fmt.Errorf("can't generate id")
	// ErrNoEntries is returned when a caller expected an entry for a query, but none was found.
	ErrNoEntries Error = fmt.Errorf("no entries")
	// ErrMultipleEntries is returned when a caller expected ONE entry for a query, but multiples were found.
	ErrMultipleEntries Error = fmt.Errorf("multiple entries")
	// ErrUnknown denotes an unknown database error.
	ErrUnknown Error = fmt.Errorf("unknown error")
)

type User

type User interface {
	// ReadUserByID returns one user.
	ReadUserByID(ctx context.Context, id string) (*models.User, Error)
	// ReadUserByEmail returns one user.
	ReadUserByEmail(ctx context.Context, email string) (*models.User, Error)
}

User contains functions related to users.

Directories

Path Synopsis
bun

Jump to

Keyboard shortcuts

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