storage

package
v0.0.0-...-1f982fd Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserExists is returned when the user already exists.
	ErrUserExists = errors.New("user already exists")
	// ErrUserNotFound is returned when the requested user is not found.
	ErrUserNotFound = errors.New("user not found")
	// ErrMetadataNotFound is returned when the requested ID is not found.
	ErrMetadataNotFound = errors.New("metadata not found")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	*DBPool
	// contains filtered or unexported fields
}

DB provides methods for interacting with the database. It encapsulates the database connection pool and configuration settings.

func Load

func Load(ctx context.Context, cfg *config.Config) (*DB, error)

Load method initializes database pool.

func (*DB) Get

func (d *DB) Get(ctx context.Context, id string) (*MetadataEntity, error)

Get method gets metadata from database.

func (*DB) GetMany

func (d *DB) GetMany(ctx context.Context) ([]*MetadataEntity, error)

func (*DB) GetUser

func (d *DB) GetUser(ctx context.Context, login string) (*UserEntity, error)

GetUser method gets user entity from database.

func (*DB) Register

func (d *DB) Register(ctx context.Context, in model.UserCredentials) (model.UserID, error)

Register method saves user into database.

func (*DB) Save

func (d *DB) Save(ctx context.Context, data model.Save) (string, error)

Save method saves user data (e.g. kind, meta) into database.

type DBPool

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

DBPool wraps a pool of connections and manages communication with the database.

func NewPool

func NewPool(ctx context.Context, dsn string) (*DBPool, error)

NewPool runs migrations and initialized new connection pool.

type MetadataEntity

type MetadataEntity struct {
	ID       string     `db:"id"`
	UserID   string     `db:"user_id"`
	Metadata string     `db:"metadata"`
	Kind     model.Kind `db:"kind"`
}

type UserEntity

type UserEntity struct {
	ID       string `db:"id"`
	Login    string `db:"login"`
	Password string `db:"id"`
}

UserEntity describes user database entity.

Jump to

Keyboard shortcuts

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