Documentation
¶
Overview ¶
Package ourdb provides a simple key-value database implementation with history tracking
Index ¶
- type Client
- func (c *Client) Add(data []byte) (uint32, error)
- func (c *Client) Close() error
- func (c *Client) Delete(id uint32) error
- func (c *Client) Destroy() error
- func (c *Client) Get(id uint32) ([]byte, error)
- func (c *Client) GetHistory(id uint32, depth uint8) ([][]byte, error)
- func (c *Client) Set(id uint32, data []byte) error
- type Location
- type LookupConfig
- type LookupTable
- func (lut *LookupTable) Delete(x uint32) error
- func (lut *LookupTable) ExportSparse(path string) error
- func (lut *LookupTable) FindLastEntry() (uint32, error)
- func (lut *LookupTable) Get(x uint32) (Location, error)
- func (lut *LookupTable) GetDataFilePath() (string, error)
- func (lut *LookupTable) GetIncFilePath() (string, error)
- func (lut *LookupTable) GetNextID() (uint32, error)
- func (lut *LookupTable) ImportSparse(path string) error
- func (lut *LookupTable) IncrementIndex() error
- func (lut *LookupTable) LocationNew(b_ []byte) (Location, error)
- func (lut *LookupTable) Set(x uint32, location Location) error
- type OurDB
- func (db *OurDB) Close() error
- func (db *OurDB) Condense() error
- func (db *OurDB) Delete(x uint32) error
- func (db *OurDB) Destroy() error
- func (db *OurDB) Get(x uint32) ([]byte, error)
- func (db *OurDB) GetHistory(x uint32, depth uint8) ([][]byte, error)
- func (db *OurDB) GetNextID() (uint32, error)
- func (db *OurDB) Load() error
- func (db *OurDB) Save() error
- func (db *OurDB) Set(args OurDBSetArgs) (uint32, error)
- type OurDBConfig
- type OurDBSetArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a simplified interface to the OurDB database
func NewClientWithConfig ¶
func NewClientWithConfig(path string, baseConfig OurDBConfig) (*Client, error)
NewClientWithConfig creates a new client with a custom configuration
func (*Client) GetHistory ¶
GetHistory retrieves historical values for the specified ID
type Location ¶
Location represents a position in a database file
func (Location) ToLookupBytes ¶
ToLookupBytes converts a Location to bytes according to the keysize
type LookupConfig ¶
LookupConfig contains configuration for the lookup table
type LookupTable ¶
LookupTable manages the mapping between IDs and data locations
func NewLookup ¶
func NewLookup(config LookupConfig) (*LookupTable, error)
NewLookup creates a new lookup table
func (*LookupTable) Delete ¶
func (lut *LookupTable) Delete(x uint32) error
Delete removes an entry from the lookup table
func (*LookupTable) ExportSparse ¶
func (lut *LookupTable) ExportSparse(path string) error
ExportSparse exports the lookup table to a file in sparse format
func (*LookupTable) FindLastEntry ¶
func (lut *LookupTable) FindLastEntry() (uint32, error)
FindLastEntry scans the lookup table to find the highest ID with a non-zero entry
func (*LookupTable) Get ¶
func (lut *LookupTable) Get(x uint32) (Location, error)
Get retrieves a location from the lookup table
func (*LookupTable) GetDataFilePath ¶
func (lut *LookupTable) GetDataFilePath() (string, error)
GetDataFilePath returns the path to the data file
func (*LookupTable) GetIncFilePath ¶
func (lut *LookupTable) GetIncFilePath() (string, error)
GetIncFilePath returns the path to the incremental file
func (*LookupTable) GetNextID ¶
func (lut *LookupTable) GetNextID() (uint32, error)
GetNextID returns the next available ID for incremental mode
func (*LookupTable) ImportSparse ¶
func (lut *LookupTable) ImportSparse(path string) error
ImportSparse imports the lookup table from a file in sparse format
func (*LookupTable) IncrementIndex ¶
func (lut *LookupTable) IncrementIndex() error
IncrementIndex increments the index for the next insertion
func (*LookupTable) LocationNew ¶
func (lut *LookupTable) LocationNew(b_ []byte) (Location, error)
LocationNew creates a new Location from bytes
type OurDB ¶
type OurDB struct {
// contains filtered or unexported fields
}
OurDB represents a binary database with variable-length records
func New ¶
func New(config OurDBConfig) (*OurDB, error)
New creates a new database with the given configuration
func (*OurDB) Condense ¶
Condense removes empty records and updates positions This is a complex operation that creates a new file without the deleted records
func (*OurDB) Delete ¶
Delete removes the data at the specified key position This operation zeros out the record but maintains the space in the file Use condense() to reclaim space from deleted records (happens in step after)
func (*OurDB) Get ¶
Get retrieves data stored at the specified key position Returns error if the key doesn't exist or data is corrupted
func (*OurDB) GetHistory ¶
GetHistory retrieves a list of previous values for the specified key depth parameter controls how many historical values to retrieve (max) Returns error if key doesn't exist or if there's an issue accessing the data
func (*OurDB) Set ¶
func (db *OurDB) Set(args OurDBSetArgs) (uint32, error)
Set stores data at the specified key position The data is stored with a CRC32 checksum for integrity verification and maintains a linked list of previous values for history tracking Returns the ID used (either x if specified, or auto-incremented if x=0)
type OurDBConfig ¶
type OurDBConfig struct { RecordNrMax uint32 RecordSizeMax uint32 FileSize uint32 Path string IncrementalMode bool Reset bool }
OurDBConfig contains configuration options for creating a new database
type OurDBSetArgs ¶
OurDBSetArgs contains the parameters for the Set method