Documentation ¶
Index ¶
- Constants
- Variables
- func IsNoObjectFound(err error) bool
- func IsUnique(err error) bool
- func NewFieldIndex(desc FieldDescriptor, opts ...int) *fieldIndex
- func UnmarshalJsonFile(path string, i interface{}) (err error)
- 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) Count(of Object) (n int, err error)
- func (db *DB) Create(o Object, s Schema) (err error)
- func (db *DB) Delete(o Object) (err error)
- func (db *DB) DeleteAll(of Object) (err error)
- func (db *DB) Drop() (err error)
- func (db *DB) Exist(o Object) (ok bool, err error)
- func (db *DB) Get(o Object) (err error)
- func (db *DB) InsertOrUpdate(o Object) (err error)
- func (db *DB) InsertOrUpdateBulk(in chan Object) (err error)
- func (db *DB) Iterator(of Object) (it *Iterator, err error)
- func (db *DB) Schema(of Object) (s *Schema, err error)
- func (db *DB) Search(o Object, field, operator string, value interface{}) *Search
- type FieldDescriptor
- type Index
- 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) 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) 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) 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 ( DefaultPermissions = fs.FileMode(0700) LowercaseNames = true )
var (
ErrEOI = errors.New("end of iterator")
)
var (
ErrNoObjectFound = errors.New("no object found")
)
var (
ErrUnknownKeyType = errors.New("unknown key type")
)
Functions ¶
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 UnmarshalJsonFile ¶
Types ¶
type DB ¶
func (*DB) Commit ¶
Commit object schema on the disk. This method must be called after Insert/Delete operations.
func (*DB) Delete ¶
Delete deletes a single Object from the database. If object is indexed DB must be committed to make the changes of the index persistent
func (*DB) DeleteAll ¶
DeleteAll deletes all Objects of the same type. If object is indexed, DB must be committed to make the changes of the index persistent
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. This function is locking the DB and will terminate only when input channel is closed
type FieldDescriptor ¶ added in v1.3.0
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) 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 Schema ¶
type Schema struct { Extension string `json:"extension"` ObjectsIndex *Index `json:"index"` // contains filtered or unexported fields }
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