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 ParseOneString ¶
func (*Ndb) All ¶
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 ¶
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 ¶
Changed reopens database files if they have been modified since last read. Returns true if the database has been changed.
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 ¶
MakeRecord creates a Record from a list of attribute-value pairs. The number of arguments must be even.
func MapSliceToRecord ¶
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 ¶
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 ¶
ParseRecord parses a single record from a string. The string should be a line containing all the attributes and values.
func SliceToRecord ¶
SliceToRecord creates a Record from a list of attribute-value pairs. The number of arguments must be even.
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.