db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = NewDB()

Functions

func Contains

func Contains[V Tableable](db *DB, name string, v V) bool

func Delete

func Delete[V Tableable](db *DB, name string, value V) error

func Get

func Get[V Tableable](db *DB, name string, v V) (*V, error)

func GetOrSet

func GetOrSet[V Tableable](db *DB, name string, value V) (*V, error)

func GetPrimaryKey

func GetPrimaryKey[V any](v V) (string, any, error)

func GetUniqueValues

func GetUniqueValues[V any](v V) (map[string]any, error)

func Iter

func Iter[V Tableable](db *DB, name string) func(yield func(any, *V) bool)

func LoadTable

func LoadTable[V Tableable](db *DB, name string, dir string) error

func Lookup

func Lookup[V Tableable](db *DB, name string, index string, v V) (*V, error)

func MarshalJSONPointer

func MarshalJSONPointer[T any](p T) ([]byte, error)

func MustGet

func MustGet[V Tableable](db *DB, name string, v V) *V

func Register

func Register[V Tableable](db *DB, name string, table table[V]) error

func SaveTable

func SaveTable[V Tableable](db *DB, name string, dir string) error

func Set

func Set[V Tableable](db *DB, name string, value V) (*V, error)

func UnmarshalJSONPointer

func UnmarshalJSONPointer[V any](b []byte, p *V) error

func Update

func Update[V Tableable](db *DB, name string, value V) (*V, error)

func Upsert

func Upsert[V Tableable](db *DB, name string, value V) (*V, error)

Types

type DB

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

func NewDB

func NewDB() *DB

type Index

type Index[V Tableable] interface {
	Index(v *V) error
	Lookup(v V) *V
}

type Indexable

type Indexable[V Tableable] interface {
	AddIndex(key string, index Index[V])
	Reindex(index string) error
	Lookup(index string, v V) *V
}

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*Map[K, V]) Contains

func (m *Map[K, V]) Contains(key K) bool

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (V, bool)

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(K, V) bool)

func (*Map[K, V]) SortedRange

func (m *Map[K, V]) SortedRange(f func(K, V) bool)

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

func (*Map[K, V]) StoreAndReturn

func (m *Map[K, V]) StoreAndReturn(key K, value V) V

type Persistent

type Persistent interface {
	Load(paths ...string) error
	Save(path string) error
}

type SimpleIndex

type SimpleIndex[V Tableable] struct {
	// contains filtered or unexported fields
}

func NewUniqueSimpleIndex

func NewUniqueSimpleIndex[V Tableable](key func(*V) []any) *SimpleIndex[V]

func (*SimpleIndex[V]) Index

func (p *SimpleIndex[V]) Index(v *V) error

func (*SimpleIndex[V]) Lookup

func (p *SimpleIndex[V]) Lookup(v V) *V

type Sort

type Sort[V Tableable] struct {
	// contains filtered or unexported fields
}

func NewSort

func NewSort[V Tableable](key func(a, b *V) int) *Sort[V]

func (*Sort[V]) Add

func (s *Sort[V]) Add(v *V)

func (*Sort[V]) Iter

func (s *Sort[V]) Iter() func(yield func(any, *V) bool)

func (*Sort[V]) Sort

func (s *Sort[V]) Sort()

type Table

type Table[V Tableable] struct {
	// contains filtered or unexported fields
}

func GetTable

func GetTable[V Tableable](db *DB, name string) (*Table[V], error)

func MustGetTable

func MustGetTable[V Tableable](db *DB, name string) *Table[V]

func NewTable

func NewTable[V Tableable]() *Table[V]

func (*Table[V]) AddIndex

func (t *Table[V]) AddIndex(key string, index Index[V])

func (*Table[V]) AddSort

func (t *Table[V]) AddSort(key string, fn func(a, b *V) int)

func (*Table[V]) Contains

func (t *Table[V]) Contains(v V) bool

func (*Table[V]) Delete

func (t *Table[V]) Delete(key V) bool

func (*Table[V]) Get

func (t *Table[V]) Get(v V) *V

func (*Table[V]) Iter

func (t *Table[V]) Iter() func(yield func(any, *V) bool)

func (*Table[V]) Len

func (t *Table[V]) Len() int

func (*Table[V]) Load

func (t *Table[V]) Load(paths ...string) error

func (*Table[V]) Lookup

func (t *Table[V]) Lookup(name string, v V) *V

func (*Table[V]) Reindex

func (t *Table[V]) Reindex(name string) error

func (*Table[V]) Resort

func (t *Table[V]) Resort(name string)

func (*Table[V]) Save

func (t *Table[V]) Save(path string) error

func (*Table[V]) Set

func (t *Table[V]) Set(value V) *V

type Tableable

type Tableable interface {
	IsPlaceholder() bool
	ResolvePointers(db *DB) (any, error)
}

Jump to

Keyboard shortcuts

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