qdb

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

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

Go to latest
Published: Mar 12, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

README

qdb - Quick DataBase

A quick & simple persistent storage database. It uses 64-bit long unique keys, to store/access a variable binary blobs.

There is a new, improved version of this project:

Documentation

Overview

Qdb is a fast persistent storage database.

The records are binary blobs that can have a variable length, up to 4GB.

The key must be a unique 64-bit value, most likely a hash of the actual key.

They data is stored on a disk, in a folder specified during the call to NewDB(). There are can be three possible files in that folder

  • qdb.0, qdb.1 - these files store a compact version of the entire database
  • qdb.log - this one stores the changes since the most recent qdb.0 or qdb.1

Index

Constants

View Source
const KeySize = 8

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {

	// If NeverKeepInMem is set to true, the engine will never keep DB records
	// in memory, but will laways need to read them from disk.
	NeverKeepInMem bool

	// Set this function if you want to be able to decide whether a specific
	// record should be kept in memory, or freed after loaded, thus will need
	// to be taken from disk whenever needed next time.
	KeepInMem func(v []byte) bool
	// contains filtered or unexported fields
}

func NewDB

func NewDB(dir string) (db *DB, e error)

Creates or opens a new database in the specified folder.

func (*DB) Browse

func (db *DB) Browse(walk func(key KeyType, value []byte) bool)

Browses through all teh DB records calling teh walk function for each record. If the walk function returns false, it aborts the browsing and returns.

func (*DB) Close

func (db *DB) Close()

Close the database. Writes all the pending changes to disk.

func (*DB) Count

func (db *DB) Count() (l int)

Returns number of records in the DB

func (*DB) Defrag

func (db *DB) Defrag() (doing bool)

Defragments the DB on the disk. Return true if defrag hes been performed, and false if was not needed.

func (*DB) Del

func (db *DB) Del(key KeyType)

Removes record with a given key.

func (*DB) Get

func (db *DB) Get(key KeyType) (value []byte)

Fetches record with a given key. Returns nil if no such record.

func (*DB) Load

func (db *DB) Load()

Loads the data from the disk into memory (cache)

func (*DB) NoSync

func (db *DB) NoSync()

Disable writing changes to disk.

func (*DB) Put

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

Adds or updates record with a given key.

func (*DB) Sync

func (db *DB) Sync()

Write all the pending changes to disk now. Re enable syncing if it has been disabled.

type KeyType

type KeyType uint64

Jump to

Keyboard shortcuts

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