persistence

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVersionGone = errors.New("version gone")

Functions

This section is empty.

Types

type InDisk

type InDisk[T any] struct {
	// contains filtered or unexported fields
}

func NewInDisk

func NewInDisk[T any](dataDir string) (*InDisk[T], error)

func (*InDisk[T]) Delete

func (f *InDisk[T]) Delete(ctx context.Context, id string) error

func (*InDisk[T]) Get

func (f *InDisk[T]) Get(ctx context.Context, id string) (*ItemWithId[T], error)

func (*InDisk[T]) List

func (f *InDisk[T]) List(ctx context.Context) ([]*ItemWithId[T], error)

func (*InDisk[T]) Put

func (f *InDisk[T]) Put(ctx context.Context, item *ItemWithId[T]) error

type InMemory

type InMemory[T any] struct {
	Items map[string]*ItemWithId[T]
	// contains filtered or unexported fields
}

func NewInMemory

func NewInMemory[T any]() *InMemory[T]

func (*InMemory[T]) Delete

func (f *InMemory[T]) Delete(ctx context.Context, id string) error

func (*InMemory[T]) Get

func (f *InMemory[T]) Get(ctx context.Context, id string) (*ItemWithId[T], error)

func (*InMemory[T]) List

func (f *InMemory[T]) List(ctx context.Context) ([]*ItemWithId[T], error)

func (*InMemory[T]) Put

func (f *InMemory[T]) Put(ctx context.Context, item *ItemWithId[T]) error

type ItemWithId

type ItemWithId[T any] struct {
	Id      string `json:"id"`
	Item    T      `bson:",inline"`
	Version int64  `json:"-" bson:"version"`
}

type Persistencer

type Persistencer[T any] interface {
	List(ctx context.Context) ([]*ItemWithId[T], error)
	Put(ctx context.Context, item *ItemWithId[T]) error
	Get(ctx context.Context, id string) (*ItemWithId[T], error)
	Delete(ctx context.Context, id string) error
}

Jump to

Keyboard shortcuts

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