Documentation ¶
Overview ¶
Package linedb provides an OO-like interface to operate on simple line-record databases backed by a plain text file.
The rules are as follows:
- One file, one database;
- One line, one record;
- An empty (0 bytes) database file contains exactly zero records;
- In all other cases, an empty line is a valid record;
- No assumptions are made about the inner structure of each record, even in terms of white space characters;
- The only special character is the record separator, '\n'.
Index ¶
- type Database
- func (db *Database) All() []Rec
- func (db *Database) Delete(number int) (string, error)
- func (db *Database) Insert(number int, record string) error
- func (db *Database) Length() int
- func (db *Database) Record(number int) (string, error)
- func (db *Database) Select(filter func(Rec) bool) []Rec
- func (db *Database) Update(number int, record string) (string, error)
- type Rec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database represents a handle to a given backing file.
func Open ¶
Open creates a handle to the given backing file.
func (*Database) All ¶
All returns all the records with their respective number
func (*Database) Delete ¶
Delete removes the number-th record from the database.
func (*Database) Insert ¶
Insert creates a new record at position n, pushing the n-th record and all subsequent records one position forward, i.e, Insert(1, ...) would create a new record at the beginning of the file.
Special case: Insert(0, ...) places the new record at the end of the file.
func (*Database) Length ¶
Length returns the number of records in the database.
func (*Database) Record ¶
Record returns the number-th record in the database. Like lines in files, records are 1-indexed.
func (*Database) Select ¶
Select returns the records which cause the filter function to return true.