byodb08

package
v0.0.0-...-9315a8a Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BNODE_NODE = 1 // internal nodes without values
	BNODE_LEAF = 2 // leaf nodes with values
)
View Source
const (
	MODE_UPSERT      = 0 // insert or replace
	MODE_UPDATE_ONLY = 1 // update existing keys
	MODE_INSERT_ONLY = 2 // only add new keys
)

update modes

View Source
const (
	TYPE_ERROR = 0
	TYPE_BYTES = 1
	TYPE_INT64 = 2
)
View Source
const BTREE_MAX_KEY_SIZE = 1000
View Source
const BTREE_MAX_VAL_SIZE = 3000
View Source
const BTREE_PAGE_SIZE = 4096
View Source
const DB_SIG = "BuildYourOwnDB08"
View Source
const FREE_LIST_CAP = (BTREE_PAGE_SIZE - FREE_LIST_HEADER) / 8
View Source
const FREE_LIST_HEADER = 8
View Source
const HEADER = 4
View Source
const TABLE_PREFIX_MIN = 100

Variables

View Source
var INTERNAL_TABLES map[string]*TableDef = map[string]*TableDef{
	"@meta":  TDEF_META,
	"@table": TDEF_TABLE,
}
View Source
var TDEF_META = &TableDef{
	Prefix: 1,
	Name:   "@meta",
	Types:  []uint32{TYPE_BYTES, TYPE_BYTES},
	Cols:   []string{"key", "val"},
	PKeys:  1,
}

internal table: metadata

View Source
var TDEF_TABLE = &TableDef{
	Prefix: 2,
	Name:   "@table",
	Types:  []uint32{TYPE_BYTES, TYPE_BYTES},
	Cols:   []string{"name", "def"},
	PKeys:  1,
}

internal table: table schemas

Functions

This section is empty.

Types

type BNode

type BNode []byte // can be dumped to the disk

type BTree

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

func (*BTree) Delete

func (tree *BTree) Delete(key []byte) bool

func (*BTree) Get

func (tree *BTree) Get(key []byte) ([]byte, bool)

func (*BTree) Update

func (tree *BTree) Update(req *UpdateReq) bool

func (*BTree) Upsert

func (tree *BTree) Upsert(key []byte, val []byte) bool

the interface

type DB

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

func (*DB) Close

func (db *DB) Close()

func (*DB) Delete

func (db *DB) Delete(table string, rec Record) (bool, error)

func (*DB) Get

func (db *DB) Get(table string, rec *Record) (bool, error)

get a single row by the primary key

func (*DB) Insert

func (db *DB) Insert(table string, rec Record) (bool, error)

func (*DB) Open

func (db *DB) Open() error

func (*DB) Set

func (db *DB) Set(table string, dbreq *DBUpdateReq) (bool, error)

add a record

func (*DB) TableNew

func (db *DB) TableNew(tdef *TableDef) error

func (*DB) Update

func (db *DB) Update(table string, rec Record) (bool, error)

func (*DB) Upsert

func (db *DB) Upsert(table string, rec Record) (bool, error)

type DBUpdateReq

type DBUpdateReq struct {
	// in
	Record Record
	Mode   int
	// out
	Updated bool
	Added   bool
}

type FreeList

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

func (*FreeList) PopHead

func (fl *FreeList) PopHead() uint64

get 1 item from the list head. return 0 on failure.

func (*FreeList) PushTail

func (fl *FreeList) PushTail(ptr uint64)

add 1 item to the tail

func (*FreeList) SetMaxSeq

func (fl *FreeList) SetMaxSeq()

make the newly added items available for consumption

type KV

type KV struct {
	Path  string
	Fsync func(int) error // overridable; for testing
	// contains filtered or unexported fields
}

func (*KV) Close

func (db *KV) Close()

cleanups

func (*KV) Del

func (db *KV) Del(key []byte) (bool, error)

func (*KV) Get

func (db *KV) Get(key []byte) ([]byte, bool)

KV interfaces

func (*KV) Open

func (db *KV) Open() error

open or create a DB file

func (*KV) Set

func (db *KV) Set(key []byte, val []byte) (bool, error)

func (*KV) Update

func (db *KV) Update(req *UpdateReq) (bool, error)

type LNode

type LNode []byte

node format: | next | pointers | unused | | 8B | n*8B | ... |

type Record

type Record struct {
	Cols []string
	Vals []Value
}

table row

func (*Record) AddInt64

func (rec *Record) AddInt64(col string, val int64) *Record

func (*Record) AddStr

func (rec *Record) AddStr(col string, val []byte) *Record

func (*Record) Get

func (rec *Record) Get(key string) *Value

type TableDef

type TableDef struct {
	// user defined
	Name  string
	Types []uint32 // column types
	Cols  []string // column names
	PKeys int      // the first `PKeys` columns are the primary key
	// auto-assigned B-tree key prefixes for different tables
	Prefix uint32
}

table schema

type UpdateReq

type UpdateReq struct {

	// out
	Added   bool   // added a new key
	Updated bool   // added a new key or an old key was changed
	Old     []byte // the value before the update
	// in
	Key  []byte
	Val  []byte
	Mode int
	// contains filtered or unexported fields
}

type Value

type Value struct {
	Type uint32
	I64  int64
	Str  []byte
}

table cell

Jump to

Keyboard shortcuts

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