collection

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Filename string // Just informative...

	Rows []*Row

	Indexes map[string]*collectionIndex // todo: protect access with mutex or use sync.Map
	// buffer   *bufio.Writer // TODO: use write buffer to improve performance (x3 in tests)
	Defaults map[string]any
	// contains filtered or unexported fields
}

func OpenCollection

func OpenCollection(filename string) (*Collection, error)

func (*Collection) Close

func (c *Collection) Close() error

func (*Collection) Drop

func (c *Collection) Drop() error

func (*Collection) DropIndex added in v0.0.4

func (c *Collection) DropIndex(name string) error

func (*Collection) FindOne

func (c *Collection) FindOne(data interface{})

func (*Collection) Index

func (c *Collection) Index(name string, options interface{}) error

IndexMap create a unique index with a name Constraints: values can be only scalar strings or array of strings

func (*Collection) Insert

func (c *Collection) Insert(item interface{}) (*Row, error)

TODO: test concurrency

func (*Collection) Patch added in v0.0.2

func (c *Collection) Patch(row *Row, patch interface{}) error

func (*Collection) Remove added in v0.0.2

func (c *Collection) Remove(r *Row) error

func (*Collection) SetDefaults added in v0.0.7

func (c *Collection) SetDefaults(defaults map[string]any) error

func (*Collection) Traverse

func (c *Collection) Traverse(f func(data []byte))

func (*Collection) TraverseRange

func (c *Collection) TraverseRange(from, to int, f func(row *Row))

type Command

type Command struct {
	Name      string          `json:"name"`
	Uuid      string          `json:"uuid"`
	Timestamp int64           `json:"timestamp"`
	StartByte int64           `json:"start_byte"`
	Payload   json.RawMessage `json:"payload"`
}

type CreateIndexCommand added in v0.0.3

type CreateIndexCommand struct {
	Name    string      `json:"name"`
	Type    string      `json:"type"`
	Options interface{} `json:"options"`
}

type CreateIndexOptions added in v0.0.3

type CreateIndexOptions struct {
	Name    string      `json:"name"`
	Type    string      `json:"type"`
	Options interface{} `json:"options"`
}

type DropIndexCommand added in v0.0.4

type DropIndexCommand struct {
	Name string `json:"name"`
}

type Index

type Index interface {
	AddRow(row *Row) error
	RemoveRow(row *Row) error
	Traverse(options []byte, f func(row *Row) bool) // todo: return error?
}

type IndexBTreeOptions added in v0.0.3

type IndexBTreeOptions struct {
	Fields []string `json:"fields"`
	Sparse bool     `json:"sparse"`
	Unique bool     `json:"unique"`
}

type IndexBtree added in v0.0.3

type IndexBtree struct {
	Btree   *btree.BTreeG[*RowOrdered]
	Options *IndexBTreeOptions
}

func NewIndexBTree added in v0.0.3

func NewIndexBTree(options *IndexBTreeOptions) *IndexBtree

func (*IndexBtree) AddRow added in v0.0.3

func (b *IndexBtree) AddRow(r *Row) error

func (*IndexBtree) RemoveRow added in v0.0.3

func (b *IndexBtree) RemoveRow(r *Row) error

func (*IndexBtree) Traverse added in v0.0.3

func (b *IndexBtree) Traverse(optionsData []byte, f func(*Row) bool)

type IndexBtreeTraverse added in v0.0.3

type IndexBtreeTraverse struct {
	Reverse bool                   `json:"reverse"`
	From    map[string]interface{} `json:"from"`
	To      map[string]interface{} `json:"to"`
}

type IndexMap added in v0.0.3

type IndexMap struct {
	Entries map[string]*Row
	RWmutex *sync.RWMutex
	Options *IndexMapOptions
}

IndexMap should be an interface to allow multiple kinds and implementations

func NewIndexMap added in v0.0.3

func NewIndexMap(options *IndexMapOptions) *IndexMap

func (*IndexMap) AddRow added in v0.0.3

func (i *IndexMap) AddRow(row *Row) error

func (*IndexMap) RemoveRow added in v0.0.3

func (i *IndexMap) RemoveRow(row *Row) error

func (*IndexMap) Traverse added in v0.0.3

func (i *IndexMap) Traverse(optionsData []byte, f func(row *Row) bool)

type IndexMapOptions added in v0.0.3

type IndexMapOptions struct {
	Field  string `json:"field"`
	Sparse bool   `json:"sparse"`
}

IndexMapOptions should have attributes like unique, sparse, multikey, sorted, background, etc... IndexMap should be an interface to have multiple indexes implementations, key value, B-Tree, bitmap, geo, cache...

type IndexMapTraverse added in v0.0.3

type IndexMapTraverse struct {
	Value string `json:"value"`
}

type Row

type Row struct {
	I       int // position in Rows
	Payload json.RawMessage
}

type RowOrdered added in v0.0.3

type RowOrdered struct {
	*Row
	Values []interface{}
}

Jump to

Keyboard shortcuts

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