mem

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IDAware

type IDAware interface {
	GetID() int64
	SetID(id int64)
}

type JSONStorage

type JSONStorage struct {
	Data     []json.RawMessage `json:"data"`
	NextID   int64             `json:"next_id"`
	Metadata map[string]any    `json:"metadata,omitempty"`
}

type MemStore

type MemStore[T IDAware] struct {
	// contains filtered or unexported fields
}

func NewMemStore

func NewMemStore[T IDAware](filePath string) (*MemStore[T], error)

NewMemStore creates a new MemStore with the specified file path

func (*MemStore[T]) Add

func (ms *MemStore[T]) Add(data T) (int64, error)

Add adds a new item with auto-generated ID

func (*MemStore[T]) Close

func (ms *MemStore[T]) Close() error

Close gracefully shuts down the MemStore and ensures final save

func (*MemStore[T]) Delete

func (ms *MemStore[T]) Delete(id int64) error

Delete removes an item by ID

func (*MemStore[T]) Get

func (ms *MemStore[T]) Get(id int64) (T, error)

Get retrieves an item by ID

func (*MemStore[T]) List

func (ms *MemStore[T]) List(options Options) ([]T, int64, error)

List returns a slice of items with pagination support

func (*MemStore[T]) Update

func (ms *MemStore[T]) Update(id int64, data T) error

Update updates an existing item or creates a new one

type Options

type Options struct {
	Limit  int
	Offset int
}

Jump to

Keyboard shortcuts

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