database

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBType

type DBType int

DBType represents the type of database of the instance, either a node's shard database or the main file database.

const (
	// FILEDB the marker for a file database.
	FILEDB DBType = iota

	// NSHARDDB is the marker for the node's shard database.
	NSHARDDB DBType = iota
)

type Database

type Database struct {
	Header types.DatabaseHeader `json:"header"` // Database header info
	Name   string               `json:"name"`   // The name of the db
	DBType DBType               // The type of database

	DB *memcache.DB // Bhojpur Cache in-memory databse instance
	// contains filtered or unexported fields
}

Database implements a general database that holds various data within meros.

func Open

func Open(dbName string, dbType DBType) (*Database, error)

Open opens the database for reading and writing. Creates a new DB if one with that name does not already exist.

func (*Database) Close

func (db *Database) Close() error

Close closes the database.

func (*Database) GetItem

func (db *Database) GetItem(id ID) (interface{}, error)

GetItem gets an item from the database.

func (*Database) PutItem

func (db *Database) PutItem(item interface{}) (ID, error)

PutItem adds a new item to the database.

func (*Database) String

func (db *Database) String() string

String marshals the DB as a string.

type ID

type ID crypto.Hash

ID represents a hash for the keys in the database.

func IDFromString

func IDFromString(s string) (ID, error)

IDFromString returns an ID given a string

func (ID) Bytes

func (id ID) Bytes() []byte

Bytes converts a given hash to a byte array.

func (ID) String

func (id ID) String() string

String returns the hash as a hex string.

Jump to

Keyboard shortcuts

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