Documentation ¶
Overview ¶
Package arnedb implements database access layer. Using this package one can embed a simple database functionality into his/her application. Arnedb is not a high performance database. There are a lot of database products which can achieve high performance. Arnedb provides a lightweight database implementation which is embeddable in any GO app. Design goals of Arnedb are: * Low memory usage: Can be run in resource constrained environments * Simplicity: Hence the title implies * Text file storage: All the data is stored in text based JSON files
Index ¶
- func GetAllAs[T any](coll *Coll, predicate func(i *T) bool) (result []*T, err error)
- func GetFirstAs[T any](coll *Coll, predicate func(i *T) bool) (result *T, err error)
- type ArneDB
- type Coll
- func (coll *Coll) Add(data interface{}) error
- func (coll *Coll) AddAll(data ...RecordInstance) (int, error)
- func (coll *Coll) Count(predicate QueryPredicate) (n int, err error)
- func (coll *Coll) DeleteAll(predicate QueryPredicate) (n int, err error)
- func (coll *Coll) DeleteFirst(predicate QueryPredicate) (n int, err error)
- func (coll *Coll) GetAll(predicate QueryPredicate) (result []RecordInstance, err error)
- func (coll *Coll) GetAllAsInterface(predicate QueryPredicateAsInterface, harvestCallback QueryPredicateAsInterface, ...) (n int, err error)
- func (coll *Coll) GetFirst(predicate QueryPredicate) (result RecordInstance, err error)
- func (coll *Coll) GetFirstAsInterface(predicate QueryPredicateAsInterface, holder interface{}) (found bool, err error)
- func (coll *Coll) ReplaceAll(predicate QueryPredicate, newData interface{}) (n int, err error)
- func (coll *Coll) ReplaceFirst(predicate QueryPredicate, newData interface{}) (n int, err error)
- func (coll *Coll) UpdateAll(predicate QueryPredicate, updateFunction UpdateFunc) (n int, err error)
- func (coll *Coll) UpdateFirst(predicate QueryPredicate, updateFunction UpdateFunc) (n int, err error)
- type QueryPredicate
- type QueryPredicateAsInterface
- type RecordInstance
- type UpdateFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArneDB ¶
type ArneDB struct { // Name is the database name Name string // contains filtered or unexported fields }
ArneDB represents a single database. There is no limit for databases. (Unless you have enough disk space)
func (*ArneDB) CreateColl ¶
CreateColl function creates a collection and returns it.
func (*ArneDB) DeleteColl ¶
DeleteColl function deletes a given collection.
func (*ArneDB) GelCollNames ¶
GelCollNames returns all present collection names as []string
type Coll ¶
type Coll struct { // Name is the collection name. Name string // contains filtered or unexported fields }
Coll represents a single collection of documents. There is no limit for collections
func (*Coll) AddAll ¶
func (coll *Coll) AddAll(data ...RecordInstance) (int, error)
AddAll function appends multiple data into a collection. If one fails, no data will be committed to storage. Thus, this function acts like a transaction. This function is a variadic function which accepts a SLICE as an argument:
d := []RecordInstance{ a, b, c} AddAll(d...)
Or can be called like:
AddAll(d1,d2,d3)
func (*Coll) Count ¶
func (coll *Coll) Count(predicate QueryPredicate) (n int, err error)
Count function returns the count of matched records with the predicate function
func (*Coll) DeleteAll ¶
func (coll *Coll) DeleteAll(predicate QueryPredicate) (n int, err error)
DeleteAll function deletes all the matches of the predicate and returns the count of deletions. n = 0 if no deletions occurred.
func (*Coll) DeleteFirst ¶
func (coll *Coll) DeleteFirst(predicate QueryPredicate) (n int, err error)
DeleteFirst function deletes the first match of the predicate and returns the count of deleted records. n = 1 if a deletion occurred, n = 0 if none.
func (*Coll) GetAll ¶
func (coll *Coll) GetAll(predicate QueryPredicate) (result []RecordInstance, err error)
GetAll function queries and gets all the matches of the query predicate.
func (*Coll) GetAllAsInterface ¶
func (coll *Coll) GetAllAsInterface(predicate QueryPredicateAsInterface, harvestCallback QueryPredicateAsInterface, holder interface{}) (n int, err error)
GetAllAsInterface function queries and gets all the matches of the query predicate. Returns the number of record found or 0 if not. Data is sent into harvestCallback function. So you can harvest the data. There is no generics in GO. So user must handle the type conversion.
func (*Coll) GetFirst ¶
func (coll *Coll) GetFirst(predicate QueryPredicate) (result RecordInstance, err error)
GetFirst function queries and gets the first match of the query. The function returns nil if no data found.
func (*Coll) GetFirstAsInterface ¶
func (coll *Coll) GetFirstAsInterface(predicate QueryPredicateAsInterface, holder interface{}) (found bool, err error)
GetFirstAsInterface function queries and gets the first match of the query. The query result can be found in the holder argument. The function returns a boolean value indicating data is found or not.
func (*Coll) ReplaceAll ¶
func (coll *Coll) ReplaceAll(predicate QueryPredicate, newData interface{}) (n int, err error)
ReplaceAll replaces all the matches of the predicate with the newData and returns the count of updates. Replace is the most costly operation. The library does not provide a method to update parts of a document since document is not known to the system.
func (*Coll) ReplaceFirst ¶
func (coll *Coll) ReplaceFirst(predicate QueryPredicate, newData interface{}) (n int, err error)
ReplaceFirst replaces the first match of the predicate with the newData and returns the count of updates. Obviously the return value is 1 if update is successful and 0 if not. Update is the most costly operation. The library does not provide a method to update parts of a document since document is not known to the system.
func (*Coll) UpdateAll ¶
func (coll *Coll) UpdateAll(predicate QueryPredicate, updateFunction UpdateFunc) (n int, err error)
UpdateAll updates all the matches of the predicate in place with the data provided by the updateFunction
func (*Coll) UpdateFirst ¶
func (coll *Coll) UpdateFirst(predicate QueryPredicate, updateFunction UpdateFunc) (n int, err error)
UpdateFirst updates the first match of predicate in place with the data provided by the updateFunction
type QueryPredicate ¶
type QueryPredicate func(instance RecordInstance) bool
QueryPredicate is a function type receiving row instance and returning bool
type QueryPredicateAsInterface ¶
type QueryPredicateAsInterface func(instance interface{}) bool
QueryPredicateAsInterface is a function type receiving record instance as given type and returning bool
type RecordInstance ¶
type RecordInstance map[string]interface{}
RecordInstance represents a record instance read from data file. It is actually a map.
type UpdateFunc ¶
type UpdateFunc func(ptrRecord *RecordInstance) *RecordInstance
UpdateFunc alters the data matched by predicate