ndb

package
v0.0.0-...-6efb5a5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

ndb provides methods to reading Plan 9 Network Database (ndb) files.

ndb files are a simple key-value storage mechanism that can be used to specify configuration information. The format also supports including other files to facilitate configuration use over different (networked) file systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ndb

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

func Open

func Open(sys ninep.FileSystem, filepath string) (*Ndb, error)

Open opens a new Ndb database from the given file path. It will recursively resolve any reference databases in the filepath.

Referenced databases can be done with a database attribute followed by file attributes in one entry:

``` database file="other.ndb" file="another.ndb" file="more.ndb" ```

Search resolves follows the ordering of files as they are specified.

func OpenOne

func OpenOne(sys ninep.FileSystem, filepath string) (*Ndb, error)

OpenOne opens a single file and returns a database. It will not recursively open other database references.

func ParseOne

func ParseOne(p []byte) (*Ndb, error)

func ParseOneString

func ParseOneString(s string) (*Ndb, error)

func (*Ndb) All

func (n *Ndb) All() iter.Seq[Record]

All returns an iterator that yields all records in the database. This isn't particularly efficient to use in production, but may be useful when debugging issues.

Use Search to find records matching a specific attribute and value instead.

func (*Ndb) AllSlice

func (n *Ndb) AllSlice() []Record

AllSlice returns a slice of all records in the database. This isn't efficient to use in production, but may be useful when debugging.

Use SearchSlice to find records matching a specific attribute and value instead.

func (*Ndb) Changed

func (n *Ndb) Changed() bool

Changed reopens database files if they have been modified since last read. Returns true if the database has been changed.

func (*Ndb) First

func (n *Ndb) First(attr, val string) Record

First returns the first record that matches the given attribute and value.

func (*Ndb) Search

func (n *Ndb) Search(preds ...SearchPredicate) iter.Seq[Record]

Search returns an iterator that yields records matching the given attribute and value.

Example:

for rec := range db.Search("person", "") {
   rec.Get("name")
}

This will yield all records with the attribute "person" like:

person name="John Doe"

func (*Ndb) SearchSlice

func (n *Ndb) SearchSlice(preds ...SearchPredicate) []Record

SearchSlice returns a slice of records matching the given attribute and value.

type Record

type Record []Tuple

func MakeRecord

func MakeRecord(avPairs ...string) Record

MakeRecord creates a Record from a list of attribute-value pairs. The number of arguments must be even.

func MapSliceToRecord

func MapSliceToRecord(m map[string][]string) Record

MapSliceToRecord converts a map of strings to a Record. The keys of the map are the attributes and the values are the values. Ordering is by sorted keys.

func MapToRecord

func MapToRecord(m map[string]string) Record

MapToRecord converts a map of strings to a Record. The keys of the map are the attributes and the values are the values. Ordering is by sorted keys.

func ParseRecord

func ParseRecord(line string) (Record, error)

ParseRecord parses a single record from a string. The string should be a line containing all the attributes and values.

func SliceToRecord

func SliceToRecord(s []string) Record

SliceToRecord creates a Record from a list of attribute-value pairs. The number of arguments must be even.

func (Record) AsMap

func (r Record) AsMap() map[string][]string

func (Record) Get

func (r Record) Get(attr string) string

func (Record) GetAll

func (r Record) GetAll(attr string) []string

func (Record) Keys

func (r Record) Keys() []string

func (Record) Lookup

func (r Record) Lookup(attr string) (string, bool)

func (Record) String

func (r Record) String() string

type SearchPredicate

type SearchPredicate interface {
	// contains filtered or unexported methods
}

func HasAttr

func HasAttr(attr string) SearchPredicate

HasAttr returns a predicate that matches records with the given attribute.

func HasAttrValue

func HasAttrValue(attr, value string) SearchPredicate

HasAttrValue returns a predicate that matches records with the given attribute and value.

type Tuple

type Tuple struct {
	Attr, Val string
}

Jump to

Keyboard shortcuts

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