ramdb

package
v0.0.0-...-af80e91 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

ramdb

RamDB is an implementation of an in-memory database with a simple API for selecting and querying the database. It uses b-trees as the underlying storage mechanism which allows fast searches and mutations.

All database commands are safe for concurrent operations.

Example

// Create database and table.
db := ramdb.NewDatabase()
_ = db.CreateTable("hotdogs", "frank_id")

// Mm, hotdogs.
type HotDog struct {
	FrankId string
	Condiments []string
	Brat bool
}

indog := HotDog{
	FrankId: "1",
	Condiments: []string{
		"kraut",
		"mustard",
	},
	Brat: true,
}

// Create a new Record and insert.
rec, _ := ramdb.NewRecord("1", "frank_id", indog)
_ = db.From("hotdogs").Insert(rec)


// Query data out.
ro, _ := db.From("hotdogs").Get("frank_id", "1")

var outdog HotDog
_ = ro.Deserialize(&outdog)

fmt.Printf("%+v\n", outdog)

// &HotDog{"1" ["kraut", "mustard"] true}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTable     = errors.New("table does not exist")
	ErrTableExists = errors.New("table already exists")

	ErrNoRecord     = errors.New("record does not exist")
	ErrRecordExists = errors.New("record already exists")

	ErrNoIndex      = errors.New("index does not exist")
	ErrInvalidIndex = errors.New("invalid index column")
	ErrIndexExists  = errors.New("index already exists")
)

Functions

func NewDatabase

func NewDatabase() *database

NewDatabase initializes a new database with no tables.

Types

type Record

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

func NewRecord

func NewRecord(key, keyColumn string, data interface{}) (*Record, error)

NewRecord returns a pointer to a Record populated with data, key, and a hash of the key used for ordering in the tree.

func (*Record) Deserialize

func (r *Record) Deserialize(into interface{}) error

Deserialize unmarshals the serialized data into `into`.

func (*Record) Less

func (r *Record) Less(than btree.Item) bool

Less is used to order items and for looking up Records in the tree.

Jump to

Keyboard shortcuts

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