collection

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StoreBackendDisk  = "disk"
	StoreBackendJSON  = "json"
	StoreBackendCrazy = "crazy"

	StoreWrapperSnappy  = "snappy"
	StoreWrapperAsync   = "async"
	StoreWrapperFlusher = "flusher"

	RecordsCorrect = "correct"
	RecordsFast    = "fast"
	RecordsHyper   = "hyper"
	RecordsTurbo   = "turbo"
	RecordsUltra   = "ultra"

	// DurabilityRelaxed acknowledges a write once it is applied in memory and
	// queued for the WAL. A crash can lose the most recent writes.
	DurabilityRelaxed = "relaxed"
	// DurabilityStrong acknowledges a write only after it is fsynced to disk,
	// so it survives a process crash or a power loss.
	DurabilityStrong = "strong"
)

Variables

View Source
var (
	ErrIndexAlreadyExists = errors.New("index already exists")
	ErrIndexNotFound      = errors.New("index not found")
	ErrIndexType          = errors.New("unknown index type")
	ErrIndexData          = errors.New("existing data does not meet the index")
)

Errors of the indexes, to check with errors.Is. Their messages say more.

View Source
var ErrCollectionClosed = errors.New("collection closed")
View Source
var ErrDocumentNotObject = errors.New("document must be a JSON object")

ErrDocumentNotObject rejects a document that is not a JSON object.

View Source
var ErrPatchNotObject = errors.New("patch must be a JSON object")

ErrPatchNotObject rejects a patch that is not a JSON object. As a merge patch (RFC 7386) it would replace the whole document with that value.

Functions

func CollectionSpecPath added in v0.0.18

func CollectionSpecPath(filename string) string

func FastUUID added in v0.0.18

func FastUUID() string

func IsCollectionSpecFile added in v0.0.18

func IsCollectionSpecFile(filename string) bool

func SaveCollectionSpec added in v0.0.18

func SaveCollectionSpec(spec CollectionSpec) error

func StartBackgroundFlusher added in v0.0.18

func StartBackgroundFlusher(store stores.Store, interval time.Duration) chan struct{}

func ValidateDurability added in v0.0.18

func ValidateDurability(durability string) error

Types

type Collection

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

func NewCollection added in v0.0.18

func NewCollection(name string, store stores.Store) *Collection

func NewCollectionBase added in v0.0.18

func NewCollectionBase(name string, store stores.Store, rr records.Records[Record]) *Collection

func NewCollectionConfigured added in v0.0.18

func NewCollectionConfigured(name string, store stores.Store, rr records.Records[Record], newRecords func() records.Records[Record]) *Collection

func OpenCollection

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

func OpenCollectionCustom added in v0.0.18

func OpenCollectionCustom(filename, rawStoreName, wrapStoreName, recordsName string) (*Collection, error)

func OpenCollectionSpec added in v0.0.18

func OpenCollectionSpec(spec CollectionSpec) (*Collection, error)

func (*Collection) Close

func (c *Collection) Close() error

func (*Collection) Commit added in v0.0.18

func (c *Collection) Commit(wait bool) error

Commit waits until every write previously made by the caller is durable (fsync) when wait is true or the collection has strong durability.

func (*Collection) Count added in v0.0.13

func (c *Collection) Count() int64

func (*Collection) CreateIndex added in v0.0.18

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

func (*Collection) DataSize added in v0.0.18

func (c *Collection) DataSize() int64

DataSize returns the size in bytes of the documents.

func (*Collection) Defaults added in v0.0.7

func (c *Collection) Defaults() map[string]any

func (*Collection) Delete added in v0.0.18

func (c *Collection) Delete(id int64, wait bool) error

func (*Collection) DeleteDeferred added in v0.0.18

func (c *Collection) DeleteDeferred(id int64) error

DeleteDeferred deletes without waiting for durability, see Commit.

func (*Collection) DropIndex added in v0.0.4

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

func (*Collection) Durability added in v0.0.18

func (c *Collection) Durability() string

func (*Collection) Filepath added in v0.0.18

func (c *Collection) Filepath() string

func (*Collection) FindOne

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

func (*Collection) Get added in v0.0.18

func (c *Collection) Get(id int64) ([]byte, bool)

func (*Collection) Index

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

func (*Collection) Insert

func (c *Collection) Insert(jsonData []byte, wait bool) (int64, error)

func (*Collection) InsertDeferred added in v0.0.18

func (c *Collection) InsertDeferred(jsonData []byte) (int64, error)

InsertDeferred inserts without waiting for durability, see Commit.

func (*Collection) InsertJSON added in v0.0.18

func (c *Collection) InsertJSON(payload []byte, wait bool) (int64, error)

func (*Collection) InsertJSONDeferred added in v0.0.18

func (c *Collection) InsertJSONDeferred(payload []byte) (int64, error)

InsertJSONDeferred inserts without waiting for durability, see Commit.

func (*Collection) InsertMap added in v0.0.18

func (c *Collection) InsertMap(item map[string]any, wait bool) (int64, error)

func (*Collection) InsertMapDeferred added in v0.0.18

func (c *Collection) InsertMapDeferred(item map[string]any) (int64, error)

InsertMapDeferred inserts without waiting for durability, see Commit.

func (*Collection) ListIndexes added in v0.0.18

func (c *Collection) ListIndexes() map[string]Index

func (*Collection) MaxID added in v0.0.18

func (c *Collection) MaxID() int64

func (*Collection) MemorySize added in v0.0.18

func (c *Collection) MemorySize() int64

MemorySize estimates the memory taken by the documents.

func (*Collection) Patch added in v0.0.2

func (c *Collection) Patch(id int64, patch interface{}, wait bool) error

func (*Collection) PatchDeferred added in v0.0.18

func (c *Collection) PatchDeferred(id int64, patch interface{}) ([]byte, error)

PatchDeferred patches without waiting for durability, see Commit. It returns the document after the patch.

func (*Collection) Recover added in v0.0.18

func (c *Collection) Recover() error

Recover lee el WAL y reconstruye el estado exacto de la base de datos

func (*Collection) Scan added in v0.0.18

func (c *Collection) Scan() *Rows

func (*Collection) SetDefaults added in v0.0.7

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

func (*Collection) SetDurability added in v0.0.18

func (c *Collection) SetDurability(durability string)

SetDurability sets how writes are acknowledged, see DurabilityStrong.

func (*Collection) SetFilepath added in v0.0.18

func (c *Collection) SetFilepath(filepath string)

func (*Collection) SyncIndexes added in v0.0.18

func (c *Collection) SyncIndexes()

func (*Collection) Traverse

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

func (*Collection) TraverseIndex added in v0.0.18

func (c *Collection) TraverseIndex(name string, options []byte, f func(id int64, data []byte) bool) error

func (*Collection) TraverseRange

func (c *Collection) TraverseRange(from, to int, f func(data []byte))

func (*Collection) TraverseRecords added in v0.0.18

func (c *Collection) TraverseRecords(f func(id int64, data []byte) bool)

func (*Collection) Update added in v0.0.18

func (c *Collection) Update(id int64, data []byte, wait bool) error

Update acts as a full payload replacement

type CollectionSpec added in v0.0.18

type CollectionSpec struct {
	Name       string      `json:"name"`
	Filename   string      `json:"-"`
	Durability string      `json:"durability,omitempty"`
	Store      StoreSpec   `json:"storage"`
	Records    RecordsSpec `json:"records"`
}

func DefaultCollectionSpec added in v0.0.18

func DefaultCollectionSpec(filename string) CollectionSpec

func LoadCollectionSpec added in v0.0.18

func LoadCollectionSpec(filename string) (CollectionSpec, bool, error)

type CreateIndexCommand added in v0.0.3

type CreateIndexCommand 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 {
	Add(id int64, data []byte) error
	Remove(id int64, data []byte) error
	Traverse(options []byte, f func(id int64, data []byte) bool)
	GetType() string
	GetOptions() interface{}
	IsUnique() bool
	// Size estimates the memory taken by the index, in O(1)
	Size() int64
}

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]
	RWmutex *sync.RWMutex

	Options *IndexBTreeOptions
	// contains filtered or unexported fields
}

func NewIndexBTree added in v0.0.3

func NewIndexBTree(options *IndexBTreeOptions) *IndexBtree

func (*IndexBtree) Add added in v0.0.18

func (b *IndexBtree) Add(id int64, data []byte) error

func (*IndexBtree) GetOptions added in v0.0.18

func (b *IndexBtree) GetOptions() interface{}

func (*IndexBtree) GetType added in v0.0.18

func (b *IndexBtree) GetType() string

func (*IndexBtree) IsUnique added in v0.0.18

func (b *IndexBtree) IsUnique() bool

func (*IndexBtree) Release added in v0.0.18

func (b *IndexBtree) Release(id int64, oldData, newData []byte)

Release removes the entry of oldData owned by id when newData uses a different key.

func (*IndexBtree) Remove added in v0.0.18

func (b *IndexBtree) Remove(id int64, data []byte) error

func (*IndexBtree) Size added in v0.0.18

func (b *IndexBtree) Size() int64

func (*IndexBtree) Traverse added in v0.0.3

func (b *IndexBtree) Traverse(optionsData []byte, f func(id int64, data []byte) 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"`
	FromExclusive map[string]interface{} `json:"from>"`
	ToExclusive   map[string]interface{} `json:"to<"`
}

type IndexFTS added in v0.0.18

type IndexFTS struct {
	Index   map[string]map[int64]struct{}
	RWmutex *sync.RWMutex
	Options *IndexFTSOptions
	// contains filtered or unexported fields
}

func NewIndexFTS added in v0.0.18

func NewIndexFTS(options *IndexFTSOptions) *IndexFTS

func (*IndexFTS) Add added in v0.0.18

func (i *IndexFTS) Add(id int64, data []byte) error

func (*IndexFTS) GetOptions added in v0.0.18

func (i *IndexFTS) GetOptions() interface{}

func (*IndexFTS) GetType added in v0.0.18

func (i *IndexFTS) GetType() string

func (*IndexFTS) IsUnique added in v0.0.18

func (i *IndexFTS) IsUnique() bool

func (*IndexFTS) Remove added in v0.0.18

func (i *IndexFTS) Remove(id int64, data []byte) error

func (*IndexFTS) Size added in v0.0.18

func (i *IndexFTS) Size() int64

func (*IndexFTS) Traverse added in v0.0.18

func (i *IndexFTS) Traverse(optionsData []byte, f func(id int64, data []byte) bool)

type IndexFTSOptions added in v0.0.18

type IndexFTSOptions struct {
	Field string `json:"field"`
}

type IndexFTSTraverse added in v0.0.18

type IndexFTSTraverse struct {
	Match string `json:"match"`
}

type IndexMap added in v0.0.3

type IndexMap struct {
	Entries map[string]*IndexMapEntry
	RWmutex *sync.RWMutex
	Options *IndexMapOptions
	// contains filtered or unexported fields
}

func NewIndexMap added in v0.0.3

func NewIndexMap(options *IndexMapOptions) *IndexMap

func (*IndexMap) Add added in v0.0.18

func (i *IndexMap) Add(id int64, data []byte) error

func (*IndexMap) GetOptions added in v0.0.18

func (i *IndexMap) GetOptions() interface{}

func (*IndexMap) GetType added in v0.0.18

func (i *IndexMap) GetType() string

func (*IndexMap) IsUnique added in v0.0.18

func (i *IndexMap) IsUnique() bool

func (*IndexMap) Release added in v0.0.18

func (i *IndexMap) Release(id int64, oldData, newData []byte)

Release removes the keys of oldData owned by id that newData no longer uses.

func (*IndexMap) Remove added in v0.0.18

func (i *IndexMap) Remove(id int64, data []byte) error

func (*IndexMap) Size added in v0.0.18

func (i *IndexMap) Size() int64

func (*IndexMap) Traverse added in v0.0.3

func (i *IndexMap) Traverse(optionsData []byte, f func(id int64, data []byte) bool)

type IndexMapEntry added in v0.0.18

type IndexMapEntry struct {
	ID int64
}

type IndexMapOptions added in v0.0.3

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

type IndexMapTraverse added in v0.0.3

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

type IndexPK added in v0.0.18

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

func NewIndexPK added in v0.0.18

func NewIndexPK(options *IndexPKOptions) *IndexPK

func (*IndexPK) Add added in v0.0.18

func (idx *IndexPK) Add(id int64, data []byte) error

func (*IndexPK) GetOptions added in v0.0.18

func (idx *IndexPK) GetOptions() interface{}

func (*IndexPK) GetType added in v0.0.18

func (idx *IndexPK) GetType() string

func (*IndexPK) IsUnique added in v0.0.18

func (idx *IndexPK) IsUnique() bool

func (*IndexPK) Release added in v0.0.18

func (idx *IndexPK) Release(id int64, oldData, newData []byte)

Release removes the key of oldData owned by id when newData uses a different key.

func (*IndexPK) Remove added in v0.0.18

func (idx *IndexPK) Remove(id int64, data []byte) error

func (*IndexPK) Size added in v0.0.18

func (idx *IndexPK) Size() int64

Size is O(shards), a constant.

func (*IndexPK) Traverse added in v0.0.18

func (idx *IndexPK) Traverse(optionsData []byte, f func(id int64, data []byte) bool)

type IndexPKOptions added in v0.0.18

type IndexPKOptions struct {
	Paths [][]string `json:"paths"`
}

type PatchPlan added in v0.0.18

type PatchPlan struct {
	Patch interface{}
	// contains filtered or unexported fields
}

func CompilePatch added in v0.0.18

func CompilePatch(patch interface{}) (*PatchPlan, error)

type Record added in v0.0.18

type Record struct {
	Data   []byte // El JSON puro
	Parsed any    // Espacio para caché del JSON parseado (Lazy)
	Active bool   // true si tiene datos, false si es un hueco
}

Record es la celda de nuestro FlatSlice

type RecordsFactory added in v0.0.18

type RecordsFactory func() records.Records[Record]

type RecordsSpec added in v0.0.18

type RecordsSpec struct {
	Engine string `json:"engine"`
}

type RowOrdered added in v0.0.3

type RowOrdered struct {
	ID     int64
	Values []interface{}
}

type Rows added in v0.0.18

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

func (*Rows) Next added in v0.0.18

func (r *Rows) Next() bool

Next avanza al siguiente registro válido (saltando huecos). Devuelve false cuando no hay más registros.

func (*Rows) Read added in v0.0.18

func (r *Rows) Read() (int64, []byte)

Read devuelve el ID y los datos del registro en el que estamos parados

type StoreFactory added in v0.0.18

type StoreFactory func(filename string) (stores.Store, error)

type StoreSpec added in v0.0.18

type StoreSpec struct {
	Backend  string             `json:"backend"`
	Wrappers []StoreWrapperSpec `json:"wrappers"`
}

type StoreWrapperFactory added in v0.0.18

type StoreWrapperFactory func(stores.Store, StoreWrapperSpec) (stores.Store, error)

type StoreWrapperSpec added in v0.0.18

type StoreWrapperSpec struct {
	Type          string        `json:"type"`
	FlushInterval time.Duration `json:"flush_interval"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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