database

package
v0.0.0-...-362a82f Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Config

type Config struct {
	PrimaryUs   string
	ReplicaEu   string
	ReplicaAsia string
	FlyRegion   string
	Logger      logging.Logger
}

type Database

type Database interface {

	// Workspace
	InsertWorkspace(ctx context.Context, newWorkspace entities.Workspace) error
	UpdateWorkspace(ctx context.Context, workspace entities.Workspace) error
	FindWorkspace(ctx context.Context, workspaceId string) (entities.Workspace, bool, error)

	// KeyAuth
	InsertKeyAuth(ctx context.Context, newKeyAuth entities.KeyAuth) error
	DeleteKeyAuth(ctx context.Context, keyAuthId string) error
	FindKeyAuth(ctx context.Context, keyAuthId string) (keyauth entities.KeyAuth, found bool, err error)

	// Api
	InsertApi(ctx context.Context, api entities.Api) error
	FindApi(ctx context.Context, apiId string) (api entities.Api, found bool, err error)
	DeleteApi(ctx context.Context, apiId string) error
	FindApiByKeyAuthId(ctx context.Context, keyAuthId string) (api entities.Api, found bool, err error)
	ListAllApis(ctx context.Context, limit int, offset int) ([]entities.Api, error)

	// Key
	InsertKey(ctx context.Context, newKey entities.Key) error
	FindKeyById(ctx context.Context, keyId string) (key entities.Key, found bool, err error)
	FindKeyByHash(ctx context.Context, hash string) (key entities.Key, found bool, err error)
	UpdateKey(ctx context.Context, key entities.Key) error
	SoftDeleteKey(ctx context.Context, keyId string) error
	DecrementRemainingKeyUsage(ctx context.Context, keyId string) (key entities.Key, err error)
	CountKeys(ctx context.Context, keyAuthId string) (int64, error)
	ListKeys(ctx context.Context, keyAuthId string, ownerId string, limit int, offset int) ([]entities.Key, error)

	// Stuff
	Close() error
}

func New

func New(config Config, middlewares ...Middleware) (Database, error)

type Middleware

type Middleware func(Database) Database

func WithMetrics

func WithMetrics(m metrics.Metrics) Middleware

func WithTracing

func WithTracing(tracer tracing.Tracer) Middleware

Jump to

Keyboard shortcuts

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