Documentation ¶
Index ¶
- Variables
- func Expand(query string) []byte
- func IsOK(query string) bool
- type Collection
- type CollectionInfo
- type DB
- type DBInfo
- type Info
- type PureDB
- func (db *PureDB) Close() error
- func (db *PureDB) Delete(name string, id int) error
- func (db *PureDB) DropCollection(name string) error
- func (db *PureDB) GetCollectionInfo(name string) CollectionInfo
- func (db *PureDB) GetInfo() DBInfo
- func (db *PureDB) Insert(name string, rec Record) (int, error)
- func (db *PureDB) InsertMany(name string, recs []Record) ([]int, error)
- func (db *PureDB) IsOpen() bool
- func (db *PureDB) MakeCollection(name string) error
- func (db *PureDB) Return(name string, id int, ptr Record) error
- func (db *PureDB) ReturnAll(name string, ptrs interface{}) (int, error)
- func (db *PureDB) Search(name string, query string, ptrs interface{}) (int, error)
- func (db *PureDB) Update(name string, id int, rec Record) error
- type Query
- type Record
- type RecordSet
- type TableInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrTableNotFound = errors.New("table not found") )
Functions ¶
Types ¶
type Collection ¶
type Collection interface {
// contains filtered or unexported methods
}
Collection is an interface representing a collection of records. It is synonymous with the notion of a table in a structured database.
type CollectionInfo ¶
type CollectionInfo interface { // GetRecords should return the total record count // along with the record id's that are currently in // this collection GetRecords() ([]int, int) // GetLastID should return the id of the record that // was last inserted GetLastID() int }
CollectionInfo is an interface representing a collection and is responsible for returning information about records located within the collection.
type DB ¶
type DB interface { // MakeCollection is used to instantiate a new collection. // It should only be used when you with to make a collection, // but will not be using it straight away. MakeCollection(collection string) error // DropCollection removes the named collection and all the // data it contains permanently. DropCollection(collection string) error // Insert inserts a single record into the named collection // using the record id provided. The returned record is loaded // into the record pointer provided. Insert(collection string, rec Record) (int, error) // InsertMany inserts multiple records and returns a set of id's // for the records that we just inserted. InsertMany(collection string, recs []Record) ([]int, error) // Return returns a single record using the id provided. The // returned record is loaded into the pointer provided. Return(collection string, id int, ptr Record) error // ReturnAll returns all the records found in the named // collection. The returned records are loaded into the // set of pointers provided. It will return the number of // records returned and a nil error on success. ReturnAll(collection string, ptrs []Record) (int, error) // Update updates the selected record in the named collection // using the id and record provided. Update(collection string, id int, rec Record) error // Delete removes a record from a collection using the // collection name and record id provided. Delete(collection string, id int) error // Search is a general purpose query method used to find // and return a set of records within a certain collection // based on the query criteria. All records in the collection // that match the provided query should be returned into the // set of record pointers provided. It returns the number of // records that matched the query and a nil error on success. Search(collection string, query string, ptrs []Record) (int, error) // GetInfo returns an instance of DBInfo which provides information // about the database. Any mutations made on the database invalidates // the last call to GetInfo. A new call to GetInfo is required to get // the most recent information. GetInfo() DBInfo // GetCollectionInfo returns an instance of CollectionInfo which // provides information for the selected collection. Any mutations // made to a collection invalidates the last call to GetInfo. A new // call to GetInfo is required to get the most recent information. GetCollectionInfo(collection string) CollectionInfo // Close synchronizes and closes the database and all collections. Close() error }
DB is an interface representing an embedded database engine that is able to perform all the basic operations necessary on collections and records.
type DBInfo ¶
type DBInfo interface { // GetCollections returns a map where the map key is the // collection name, and the map value is an instance of // CollectionInfo for the named collection. GetCollections() map[string]CollectionInfo }
DBInfo is an interface representing a database and is responsible for returning information about the database, collections and records.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
func (*Info) GetCollections ¶
func (i *Info) GetCollections() map[string]CollectionInfo
type PureDB ¶
type PureDB struct {
// contains filtered or unexported fields
}
PureDB is a simple embedded database engine that stores records encoded in NDJSON or JSONL format.
func (*PureDB) Delete ¶
Delete takes a table name and a record id and removes the record that has a matching id.
func (*PureDB) DropCollection ¶
DropCollection takes a table name and completely deletes all data within the table and removes the table file itself. It returns an error if the table is not found, or if there was trouble deleting it.
func (*PureDB) GetCollectionInfo ¶
func (db *PureDB) GetCollectionInfo(name string) CollectionInfo
func (*PureDB) Insert ¶
Insert takes a table name and a struct that implements the Record interface and adds a new record to the table. It will add duplicate records. It returns the ID of the record that was just added.
func (*PureDB) MakeCollection ¶
MakeCollection takes a table name and creates and initializes a new table. It returns an error if the table is already created. CreateTable should only be used in rare cases if you wish to initialize a table, but you are not going to use it right away.
func (*PureDB) Return ¶
Return takes a table name and a pointer to a struct that implements the Record interface. The found record is unmarshalled into the provided pointer. If the provided id cannot be found or does not match a record in the table an ErrRecordNotFound error is returned.
func (*PureDB) ReturnAll ¶
ReturnAll returns all the records found in the named collection. The returned records are loaded into the set of pointers provided. It will return the number of records returned and a nil error on success.
type Record ¶
type Record interface { // GetID should return the id of the record GetID() int // SetID should set the id of the record by // using the id provided SetID(id int) }
Record is an interface representing a single record able to be used by a collection.