storage

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PGError_ForeignKeyViolation      = "23503"
	PGError_CheckConstraintViolation = "23514"
)

Taken from https://www.postgresql.org/docs/current/errcodes-appendix.html

Variables

View Source
var (
	ErrUnknownShelfError = errors.New("unknown shelf")
	ErrUnknownBookError  = errors.New("unknown book")
	ErrNotFoundError     = errors.New("not found")
)

Functions

func DBBookMetadataToPBMetadata added in v0.1.0

func DBBookMetadataToPBMetadata(row DBBookMetadata) *pbv1.Metadata

func DBOutputBookToPBBook added in v0.1.0

func DBOutputBookToPBBook(row DBOutputBook) *pbv1.Book

func DBShelfToPBShelf added in v0.1.0

func DBShelfToPBShelf(row DBShelf) *pbv1.Shelf

Types

type DBBookContent added in v0.1.0

type DBBookContent struct {
	BookID  string `db:"book_id"`
	Format  string `db:"format"`
	Content []byte `db:"content"`
}

type DBBookMetadata added in v0.1.0

type DBBookMetadata struct {
	ID           string            `db:"id"`
	Title        string            `db:"title"`
	Author       sql.Null[string]  `db:"author"`
	Series       sql.Null[string]  `db:"series"`
	SeriesNumber sql.Null[float32] `db:"series_number"`
	UploadTS     time.Time         `db:"upload_ts"`
}

func PBMetadataToDBBookMetadata added in v0.1.0

func PBMetadataToDBBookMetadata(metadata *pbv1.Metadata) DBBookMetadata

type DBBookTag added in v0.1.0

type DBBookTag struct {
	BookID string `db:"book_id"`
	Tag    string `db:"tag"`
}

type DBOutputBook added in v0.1.0

type DBOutputBook struct {
	DBBookMetadata
	Content []byte `db:"content"`
}

type DBShelf added in v0.1.0

type DBShelf struct {
	ID   string `db:"id"`
	Name string `db:"name"`
}

func PBShelfToDBShelf added in v0.1.0

func PBShelfToDBShelf(shelf *pbv1.Shelf) DBShelf

type DBShelfMember added in v0.1.0

type DBShelfMember struct {
	ShelfID string `db:"shelf_id"`
	BookID  string `db:"book_id"`
}

func PBAddShelfBooksRequestToDBShelfMembers added in v0.1.0

func PBAddShelfBooksRequestToDBShelfMembers(req *pbv1.AddBooksToShelfRequest) []DBShelfMember

type ListMetadataResponse added in v0.5.0

type ListMetadataResponse struct {
	Books   []*pbv1.Metadata
	HasMore bool
}

type Memory

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

func NewMemory

func NewMemory(conf MemoryConfig) *Memory

func (*Memory) AddBook

func (m *Memory) AddBook(ctx context.Context, req *pbv1.AddBookRequest) error

func (*Memory) AddBooksToShelf

func (m *Memory) AddBooksToShelf(ctx context.Context, req *pbv1.AddBooksToShelfRequest) error

func (*Memory) CreateShelf

func (m *Memory) CreateShelf(ctx context.Context, shelf *pbv1.Shelf) error

func (*Memory) GetAllSeries

func (m *Memory) GetAllSeries(ctx context.Context) ([]string, error)

func (*Memory) GetBooksBySeries

func (m *Memory) GetBooksBySeries(ctx context.Context, series string) ([]*pbv1.Metadata, error)

func (*Memory) ListBooksForShelf

func (m *Memory) ListBooksForShelf(ctx context.Context, req *pbv1.ListBooksForShelfRequest) ([]*pbv1.Metadata, error)

func (*Memory) ListMetadata

func (m *Memory) ListMetadata(ctx context.Context, req *pbv1.ListBooksRequest) (*ListMetadataResponse, error)

func (*Memory) ListShelves

func (m *Memory) ListShelves(ctx context.Context) ([]*pbv1.Shelf, error)

func (*Memory) Purge

func (m *Memory) Purge(ctx context.Context) error

func (*Memory) ReadBook

func (m *Memory) ReadBook(ctx context.Context, id string) (*pbv1.Book, error)

func (*Memory) RemoveBook

func (m *Memory) RemoveBook(ctx context.Context, req *pbv1.RemoveBookRequest) error

func (*Memory) RemoveBooksFromShelf

func (m *Memory) RemoveBooksFromShelf(ctx context.Context, req *pbv1.RemoveBooksFromShelfRequest) error

type MemoryConfig

type MemoryConfig struct{}

type Postgres added in v0.1.0

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

func NewPostgres added in v0.1.0

func NewPostgres(conf PostgresConfig) *Postgres

func (*Postgres) AddBook added in v0.1.0

func (p *Postgres) AddBook(ctx context.Context, req *pbv1.AddBookRequest) error

func (*Postgres) AddBooksToShelf added in v0.1.0

func (p *Postgres) AddBooksToShelf(ctx context.Context, req *pbv1.AddBooksToShelfRequest) error

func (*Postgres) CreateShelf added in v0.1.0

func (p *Postgres) CreateShelf(ctx context.Context, shelf *pbv1.Shelf) error

func (*Postgres) GetAllSeries added in v0.1.0

func (p *Postgres) GetAllSeries(ctx context.Context) ([]string, error)

func (*Postgres) GetBooksBySeries added in v0.1.0

func (p *Postgres) GetBooksBySeries(ctx context.Context, series string) ([]*pbv1.Metadata, error)

func (*Postgres) ListBooksForShelf added in v0.1.0

func (p *Postgres) ListBooksForShelf(ctx context.Context, req *pbv1.ListBooksForShelfRequest) ([]*pbv1.Metadata, error)

func (*Postgres) ListMetadata added in v0.1.0

func (p *Postgres) ListMetadata(ctx context.Context, req *pbv1.ListBooksRequest) (*ListMetadataResponse, error)

func (*Postgres) ListShelves added in v0.1.0

func (p *Postgres) ListShelves(ctx context.Context) ([]*pbv1.Shelf, error)

func (*Postgres) Purge added in v0.1.0

func (p *Postgres) Purge(ctx context.Context) error

func (*Postgres) ReadBook added in v0.1.0

func (p *Postgres) ReadBook(ctx context.Context, id string) (*pbv1.Book, error)

func (*Postgres) RemoveBook added in v0.1.0

func (p *Postgres) RemoveBook(ctx context.Context, req *pbv1.RemoveBookRequest) error

func (*Postgres) RemoveBooksFromShelf added in v0.1.0

func (p *Postgres) RemoveBooksFromShelf(ctx context.Context, req *pbv1.RemoveBooksFromShelfRequest) error

type PostgresConfig added in v0.1.0

type PostgresConfig struct {
	DB *sql.DB
}

type Storer

type Storer interface {
	Purge(ctx context.Context) error
	AddBook(ctx context.Context, req *pbv1.AddBookRequest) error
	ReadBook(ctx context.Context, id string) (*pbv1.Book, error)
	RemoveBook(ctx context.Context, req *pbv1.RemoveBookRequest) error
	ListMetadata(ctx context.Context, req *pbv1.ListBooksRequest) (*ListMetadataResponse, error)
	GetAllSeries(ctx context.Context) ([]string, error)
	GetBooksBySeries(ctx context.Context, series string) ([]*pbv1.Metadata, error)
	CreateShelf(ctx context.Context, shelf *pbv1.Shelf) error
	ListShelves(ctx context.Context) ([]*pbv1.Shelf, error)
	AddBooksToShelf(ctx context.Context, req *pbv1.AddBooksToShelfRequest) error
	RemoveBooksFromShelf(ctx context.Context, req *pbv1.RemoveBooksFromShelfRequest) error
	ListBooksForShelf(ctx context.Context, req *pbv1.ListBooksForShelfRequest) ([]*pbv1.Metadata, error)
}

func NewFromEnv

func NewFromEnv(logger zerolog.Logger) (Storer, func(), error)

Jump to

Keyboard shortcuts

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