Documentation ¶
Index ¶
- Constants
- Variables
- func CamelToSnake(camel string) string
- func IsNoObjectFound(err error) bool
- func IsUnique(err error) bool
- func NewFieldIndex(desc FieldDescriptor, opts ...int) *fieldIndex
- func ToObjectChan(slice interface{}) (objs chan Object)
- func UnmarshalJsonFile(path string, i interface{}) (err error)
- func ValidationErr(o Object, err error) error
- type Async
- type Constraints
- type DB
- func (db *DB) All(of Object) (out []Object, err error)
- func (db *DB) Close() (last error)
- func (db *DB) Commit(o Object) (err error)
- func (db *DB) Control() (err error)
- func (db *DB) Count(of Object) (n int, err error)
- func (db *DB) Create(o Object, s Schema) (err error)
- func (db *DB) Delete(o Object) (lastErr error)
- func (db *DB) DeleteAll(of Object) (err error)
- func (db *DB) DeleteObjects(from *Iterator) (err error)
- func (db *DB) Drop() (err error)
- func (db *DB) Exist(o Object) (ok bool, err error)
- func (db *DB) Flush(o Object) (err error)
- func (db *DB) FlushAll(of Object) (err error)
- func (db *DB) Get(in Object) (out Object, err error)
- func (db *DB) GetByUUID(in Object, uuid string) (out Object, err error)
- func (db *DB) InsertOrUpdate(o Object) (err error)
- func (db *DB) InsertOrUpdateBulk(in chan Object, csize int) (err error)
- func (db *DB) InsertOrUpdateMany(objects ...Object) (err error)
- func (db *DB) Iterator(of Object) (it *Iterator, err error)
- func (db *DB) Lock()
- func (db *DB) RLock()
- func (db *DB) RUnlock()
- func (db *DB) Schema(of Object) (s *Schema, err error)
- func (db *DB) Search(o Object, field, operator string, value interface{}) *Search
- func (db *DB) Unlock()
- type FieldDescriptor
- type Index
- func (in *Index) Control() error
- func (in *Index) Delete(o Object)
- func (in *Index) InsertOrUpdate(o Object) (err error)
- func (in *Index) Len() int
- func (in *Index) MarshalJSON() ([]byte, error)
- func (in *Index) SatisfyAll(o Object) (err error)
- func (in *Index) Search(o Object, field string, operator string, value interface{}, ...) ([]*IndexedField, error)
- func (in *Index) UnmarshalJSON(data []byte) error
- type IndexedField
- func (f *IndexedField) DeepEqual(other *IndexedField) bool
- func (f *IndexedField) Equal(other *IndexedField) bool
- func (f *IndexedField) Evaluate(operator string, other *IndexedField) bool
- func (f *IndexedField) Greater(other *IndexedField) bool
- func (f *IndexedField) Less(other *IndexedField) bool
- func (f *IndexedField) MarshalJSON() ([]byte, error)
- func (f *IndexedField) String() string
- func (f *IndexedField) UnmarshalJSON(data []byte) error
- func (f *IndexedField) ValueTypeFromString(t string)
- func (f *IndexedField) ValueTypeString() string
- type Item
- type Iterator
- type Object
- type Schema
- type Search
- func (s *Search) And(field, operator string, value interface{}) *Search
- func (s *Search) Collect() (out []Object, err error)
- func (s *Search) Delete() (err error)
- func (s *Search) Err() error
- func (s *Search) Iterator() (it *Iterator, err error)
- func (s *Search) Len() int
- func (s *Search) Limit(limit uint64) *Search
- func (s *Search) One() (o Object, err error)
- func (s *Search) Operation(operator, field, comparator string, value interface{}) *Search
- func (s *Search) Or(field, operator string, value interface{}) *Search
- func (s *Search) Reverse() *Search
Constants ¶
const (
SchemaFilename = "schema.json"
)
Variables ¶
var ( ErrUnkownField = errors.New("unknown object field") ErrFieldNotIndexed = errors.New("field not indexed") ErrFieldUnique = errors.New("unique constraint on field") ErrUnkownSearchOperator = errors.New("unknown search operator") )
var ( ErrBadSchema = errors.New("schema must be a file") ErrMissingObjIndex = errors.New("schema is missing object index") DefaultSchema = Schema{Extension: ".json"} )
var ( ErrUnknownOperator = errors.New("unknown logical operator") ErrNoObjectFound = errors.New("no object found") )
var ( DefaultPermissions = fs.FileMode(0700) LowercaseNames = true )
var (
ErrEOI = errors.New("end of iterator")
)
var (
ErrInvalidObject = errors.New("object is not valid")
)
var (
ErrUnknownKeyType = errors.New("unknown key type")
)
Functions ¶
func CamelToSnake ¶ added in v1.6.0
func IsNoObjectFound ¶ added in v1.3.0
func NewFieldIndex ¶
func NewFieldIndex(desc FieldDescriptor, opts ...int) *fieldIndex
NewFieldIndex returns an empty initialized slice. Opts takes len and cap in order to initialize the underlying slice
func ToObjectChan ¶ added in v1.6.1
func ToObjectChan(slice interface{}) (objs chan Object)
ToObjectChan is a convenient function to pre-process arguments passed to InsertOrUpdateMany function.
func UnmarshalJsonFile ¶
func ValidationErr ¶ added in v1.6.1
Types ¶
type Async ¶ added in v1.5.0
type Async struct { Enable bool Threshold int Timeout time.Duration // contains filtered or unexported fields }
func (*Async) MarshalJSON ¶ added in v1.5.0
func (*Async) UnmarshalJSON ¶ added in v1.5.0
type Constraints ¶ added in v1.4.0
type Constraints struct {
Unique bool `json:"unique"`
}
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) Close ¶
Close closes gently the DB by flushing any pending async writes and by committing all the schemas to disk
func (*DB) Commit ¶
Commit object schema on the disk. This method must be called after Insert/Delete operations.
func (*DB) DeleteObjects ¶ added in v1.4.0
DeleteObjects deletes Objects from an Iterator and commit changes. This primitive can be used for bulk deletions.
func (*DB) FlushAll ¶ added in v1.5.0
FlushAll objects of type to disk. As Flush this function does not commit schema to disk
func (*DB) InsertOrUpdate ¶
InsertOrUpdate inserts or updates a single Object and commits changes. This method is not suited for bulk insertions as each insert will trigger a write overhead. For bulk insertion use InsertOrUpdateBulk function
func (*DB) InsertOrUpdateBulk ¶
InsertOrUpdateBulk inserts objects in bulk in the DB. A chunk size needs to be provided to commit the DB at every chunk. The DB is locked at every chunk processed, so changing the chunk size impact other concurrent DB operations.
func (*DB) InsertOrUpdateMany ¶ added in v1.5.0
InsertOrUpdateMany inserts several objects into the DB and commit schema after all insertions. It is faster than calling InsertOrUpdate for every objects separately.
type FieldDescriptor ¶ added in v1.3.0
type FieldDescriptor struct { Name string `json:"-"` Index bool `json:"-"` Constraint Constraints `json:"constraint"` }
type Index ¶
type Index struct { Fields map[string]*fieldIndex // mapping ObjectId -> Object UUID ObjectIds map[uint64]string // contains filtered or unexported fields }
func NewIndex ¶
func NewIndex(fields ...FieldDescriptor) *Index
func (*Index) InsertOrUpdate ¶
func (*Index) MarshalJSON ¶
func (*Index) SatisfyAll ¶ added in v1.4.0
func (*Index) Search ¶
func (in *Index) Search(o Object, field string, operator string, value interface{}, constrain []*IndexedField) ([]*IndexedField, error)
func (*Index) UnmarshalJSON ¶
type IndexedField ¶
type IndexedField struct { // the value we want to index Value interface{} // the ObjectId of the object in the list of object // it must be unique accross one ObjectId ObjectId uint64 }
func NewIndexedField ¶
func NewIndexedField(value interface{}, objid uint64) (*IndexedField, error)
func (*IndexedField) DeepEqual ¶
func (f *IndexedField) DeepEqual(other *IndexedField) bool
func (*IndexedField) Equal ¶
func (f *IndexedField) Equal(other *IndexedField) bool
func (*IndexedField) Evaluate ¶
func (f *IndexedField) Evaluate(operator string, other *IndexedField) bool
func (*IndexedField) Greater ¶
func (f *IndexedField) Greater(other *IndexedField) bool
func (*IndexedField) Less ¶
func (f *IndexedField) Less(other *IndexedField) bool
func (*IndexedField) MarshalJSON ¶
func (f *IndexedField) MarshalJSON() ([]byte, error)
func (*IndexedField) String ¶
func (f *IndexedField) String() string
func (*IndexedField) UnmarshalJSON ¶
func (f *IndexedField) UnmarshalJSON(data []byte) error
func (*IndexedField) ValueTypeFromString ¶
func (f *IndexedField) ValueTypeFromString(t string)
func (*IndexedField) ValueTypeString ¶
func (f *IndexedField) ValueTypeString() string
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
func (*Item) Initialize ¶
type Object ¶
func ToObjectSlice ¶ added in v1.5.1
func ToObjectSlice(slice interface{}) (objs []Object)
ToObjectSlice is a convenient function to pre-process arguments passed to InsertOrUpdateMany function.
type Schema ¶
type Schema struct { Extension string `json:"extension"` Cache bool `json:"cache"` AsyncWrites *Async `json:"async-writes,omitempty"` ObjectsIndex *Index `json:"index"` // contains filtered or unexported fields }
func (*Schema) Asynchrone ¶ added in v1.6.3
Asynchrone makes the data described by this schema managed asynchronously Objects will be written either if more than threshold events are modified or at every timeout
func (*Schema) Initialize ¶
type Search ¶
type Search struct {
// contains filtered or unexported fields
}
Search helper structure to easily build search queries on objects and retrieve the results
func (*Search) Collect ¶
Collect all the objects resulting from the search. If a search has been made on an indexed field, results will be in descending order by default. If you want to change result order, call Reverse before. NB: only search on indexed field(s) will be garanteed to be ordered according to the last field searched.
func (*Search) Iterator ¶
Iterator returns an Iterator convenient to iterate over the objects resulting from the search
func (*Search) One ¶ added in v1.3.0
One returns the first result found calling Collect function. If no Object is found, ErrNoObjectFound is returned
func (*Search) Operation ¶ added in v1.6.3
Operation performs a new Search while ANDing or ORing the results operator must be in ["and", "&&", "or", "||"]