godb

package module
v0.0.0-...-a65e6e2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)

Variables

View Source
var (
	ErrEmptyKey      = errors.New("empty key")
	ErrKeyTooLarge   = errors.New("key size is too large")
	ErrValueTooLarge = errors.New("value size is too large")

	ErrInvalidKey     = errors.New("invalid key")
	ErrInvalidTTL     = errors.New("invalid ttl")
	ErrExpiredKey     = errors.New("key has expired")
	ErrTxClosed       = errors.New("tx closed")
	ErrDatabaseClosed = errors.New("database closed")
	ErrTxNotWritable  = errors.New("tx not writable")
)
View Source
var (
	ErrInvalidSegment        = errors.New("invalid segment")
	ErrInvalidSegmentVersion = errors.New("invalid segment version")
	ErrSegmentNotWritable    = errors.New("segment not writable")
	ErrSegmentTooLarge       = errors.New("segment too large")
	ErrKeyNotFound           = errors.New("key not found")
)
View Source
var (
	ErrInvalidRecord = errors.New("invalid record")
)

Functions

This section is empty.

Types

type DB

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

func Open

func Open(dbpath string, options ...Option) (*DB, error)

Open opens a database at the given path.

func (*DB) Begin

func (db *DB) Begin(writable bool) (*Tx, error)

func (*DB) Close

func (db *DB) Close() error

Close releases all db resources.

func (*DB) Delete

func (db *DB) Delete(key []byte) error

func (*DB) Get

func (db *DB) Get(key []byte) ([]byte, error)

Get gets the value of the key from the db

func (*DB) Put

func (db *DB) Put(key, value []byte) error

Put put the value of the key to the db

func (*DB) Update

func (db *DB) Update(fn func(tx *Tx) error) error

Update executes a function within a managed read/write transaction. The transaction has been committed when no error is returned. In the event that an error is returned, the transaction will be rolled back. When a non-nil error is returned from the function, the transaction will be rolled back and the that error will be return to the caller of Update().

func (*DB) View

func (db *DB) View(fn func(tx *Tx) error) error

View executes a function within a managed read-only transaction. When a non-nil error is returned from the function that error will be return to the caller of View().

type Option

type Option func(*option) error

func WithFsync

func WithFsync(fsync bool) Option

func WithSegmentSize

func WithSegmentSize(s int64) Option

type Tx

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

Tx represents a transaction on the database. This transaction can either be read-only or read/write. Read-only transactions can be used for retrieving values for keys and iterating through keys and values. Read/write transactions can set and delete keys.

All transactions must be committed or rolled-back when done.

func (*Tx) Commit

func (tx *Tx) Commit() error

func (*Tx) Put

func (tx *Tx) Put(key, value []byte) error

Set saves a key-value pair.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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