db

package
v0.0.0-...-0f594a8 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrAlreadyExists

func NewErrAlreadyExists(msg string) error

NewErrAlreadyExists wraps a message in an AlreadyExistsError object.

Types

type AlreadyExistsError

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

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

func (*AlreadyExistsError) Error

func (e *AlreadyExistsError) Error() string

Error returns the error message as a string.

type DB

type DB interface {
	CreateAccount(ctx context.Context, account *models.Account) Error
	IncAccountLoginCount(ctx context.Context, account *models.Account) Error
	ReadAccount(ctx context.Context, id int64) (*models.Account, Error)
	ReadAccountByUsername(ctx context.Context, username string, instanceID int64) (*models.Account, Error)
	UpdateAccount(ctx context.Context, account *models.Account) Error

	CountInstances(ctx context.Context) (int64, Error)
	CreateInstance(ctx context.Context, instance *models.Instance) Error
	ReadInstance(ctx context.Context, id int64) (*models.Instance, Error)
	ReadInstanceByDomain(ctx context.Context, domain string) (*models.Instance, Error)
	ReadInstancesPage(ctx context.Context, index, count int) ([]*models.Instance, Error)
	UpdateInstance(ctx context.Context, instance *models.Instance) Error

	CountTags(ctx context.Context) (int64, Error)
	CreateTag(ctx context.Context, tag *models.Tag) Error
	ReadTag(ctx context.Context, id int64) (*models.Tag, Error)
	ReadTagByName(ctx context.Context, name string) (*models.Tag, Error)
	ReadTagsPage(ctx context.Context, index, count int) ([]*models.Tag, Error)
	UpdateTag(ctx context.Context, tag *models.Tag) Error

	// Close closes the db connections
	Close(ctx context.Context) Error
	// DoMigration runs database migrations
	DoMigration(ctx context.Context) Error
}

DB represents a database client.

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")
)

Directories

Path Synopsis
bun

Jump to

Keyboard shortcuts

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