Documentation ¶
Index ¶
- Constants
- Variables
- func NewDefaultStorage() *storageImpl
- func NewObjectId() string
- type Config
- type CriteriaNormalizeVisitor
- type DB
- func (db *DB) Close() error
- func (db *DB) Count(q *query.Query) (int, error)
- func (db *DB) CreateCollection(name string) error
- func (db *DB) CreateIndex(collection, field string) error
- func (db *DB) Delete(q *query.Query) error
- func (db *DB) DeleteById(collection string, id string) error
- func (db *DB) DropCollection(name string) error
- func (db *DB) DropIndex(collection, field string) error
- func (db *DB) Exists(q *query.Query) (bool, error)
- func (db *DB) ExportCollection(collectionName string, exportPath string) error
- func (db *DB) FindAll(q *query.Query) ([]*d.Document, error)
- func (db *DB) FindById(collection string, id string) (*d.Document, error)
- func (db *DB) FindFirst(q *query.Query) (*d.Document, error)
- func (db *DB) ForEach(q *query.Query, consumer func(_ *d.Document) bool) error
- func (db *DB) HasCollection(name string) (bool, error)
- func (db *DB) HasIndex(collection, field string) (bool, error)
- func (db *DB) ImportCollection(collectionName string, importPath string) error
- func (db *DB) Insert(collectionName string, docs ...*d.Document) error
- func (db *DB) InsertOne(collectionName string, doc *d.Document) (string, error)
- func (db *DB) ListCollections() ([]string, error)
- func (db *DB) ListIndexes(collection string) ([]index.IndexInfo, error)
- func (db *DB) ReplaceById(collection, docId string, doc *d.Document) error
- func (db *DB) Save(collectionName string, doc *d.Document) error
- func (db *DB) Update(q *query.Query, updateMap map[string]interface{}) error
- func (db *DB) UpdateById(collection, docId string, updateMap map[string]interface{}) error
- func (db *DB) UpdateFunc(q *query.Query, updateFunc func(doc *d.Document) *d.Document) error
- type FieldRangeVisitor
- type IndexSelectVisitor
- type NotFlattenVisitor
- type Option
- type StorageEngine
Constants ¶
const ( GCReclaimIntervalDefault = time.Minute * 5 GCDiscardRatioDefault = 0.5 )
Variables ¶
var ( ErrCollectionExist = errors.New("collection already exist") ErrCollectionNotExist = errors.New("no such collection") ErrIndexExist = errors.New("index already exist") ErrIndexNotExist = errors.New("no such index") )
Collection creation errors
var ErrDocumentNotExist = errors.New("no such document")
var ErrDuplicateKey = errors.New("duplicate key")
Functions ¶
func NewDefaultStorage ¶
func NewDefaultStorage() *storageImpl
func NewObjectId ¶
func NewObjectId() string
Types ¶
type CriteriaNormalizeVisitor ¶
type CriteriaNormalizeVisitor struct {
// contains filtered or unexported fields
}
func (*CriteriaNormalizeVisitor) VisitBinaryCriteria ¶
func (v *CriteriaNormalizeVisitor) VisitBinaryCriteria(c *query.BinaryCriteria) interface{}
func (*CriteriaNormalizeVisitor) VisitNotCriteria ¶
func (v *CriteriaNormalizeVisitor) VisitNotCriteria(c *query.NotCriteria) interface{}
func (*CriteriaNormalizeVisitor) VisitUnaryCriteria ¶
func (v *CriteriaNormalizeVisitor) VisitUnaryCriteria(c *query.UnaryCriteria) interface{}
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents the entry point of each clover database.
func Open ¶
Open opens a new clover database on the supplied path. If such a folder doesn't exist, it is automatically created.
func (*DB) Close ¶
Close releases all the resources and closes the database. After the call, the instance will no more be usable.
func (*DB) Count ¶
Count returns the number of documents which satisfy the query (i.e. len(q.FindAll()) == q.Count()).
func (*DB) CreateCollection ¶
CreateCollection creates a new empty collection with the given name.
func (*DB) CreateIndex ¶
CreateIndex creates an index for the specified for the specified (index, collection) pair.
func (*DB) DeleteById ¶
DeleteById removes the document with the given id from the underlying collection, provided that such a document exists and satisfies the underlying query.
func (*DB) DropCollection ¶
DropCollection removes the collection with the given name, deleting any content on disk.
func (*DB) DropIndex ¶
DropIndex deletes the idex, is such index exists for the specified (index, collection) pair.
func (*DB) ExportCollection ¶
ExportCollection exports an existing collection to a JSON file.
func (*DB) FindById ¶
FindById returns the document with the given id, if such a document exists and satisfies the underlying query, or null.
func (*DB) ForEach ¶
ForEach runs the consumer function for each document matching the provied query. If false is returned from the consumer function, then the iteration is stopped.
func (*DB) HasCollection ¶
HasCollection returns true if and only if the database contains a collection with the given name.
func (*DB) HasIndex ¶
HasIndex returns true if an idex exists for the specified (index, collection) pair.
func (*DB) ImportCollection ¶
ImportCollection imports a collection from a JSON file.
func (*DB) InsertOne ¶
InsertOne inserts a single document to an existing collection. It returns the id of the inserted document.
func (*DB) ListCollections ¶
ListCollections returns a slice of strings containing the name of each collection stored in the db.
func (*DB) ListIndexes ¶
ListIndexes returns a list containing the names of all the indexes for the specified collection.
func (*DB) ReplaceById ¶
ReplaceById replaces the document with the specified id with the one provided. If no document exists, an ErrDocumentNotExist is returned.
func (*DB) Update ¶
Update updates all the document selected by q using the provided updateMap. Each update is specified by a mapping fieldName -> newValue.
func (*DB) UpdateById ¶
UpdateById updates the document with the specified id using the supplied update map. If no document with the specified id exists, an ErrDocumentNotExist is returned.
type FieldRangeVisitor ¶
func NewFieldRangeVisitor ¶
func NewFieldRangeVisitor(fields []string) *FieldRangeVisitor
func (*FieldRangeVisitor) VisitBinaryCriteria ¶
func (v *FieldRangeVisitor) VisitBinaryCriteria(c *query.BinaryCriteria) interface{}
func (*FieldRangeVisitor) VisitNotCriteria ¶
func (v *FieldRangeVisitor) VisitNotCriteria(c *query.NotCriteria) interface{}
func (*FieldRangeVisitor) VisitUnaryCriteria ¶
func (v *FieldRangeVisitor) VisitUnaryCriteria(c *query.UnaryCriteria) interface{}
type IndexSelectVisitor ¶
func (*IndexSelectVisitor) VisitBinaryCriteria ¶
func (v *IndexSelectVisitor) VisitBinaryCriteria(c *query.BinaryCriteria) interface{}
func (*IndexSelectVisitor) VisitNotCriteria ¶
func (v *IndexSelectVisitor) VisitNotCriteria(c *query.NotCriteria) interface{}
func (*IndexSelectVisitor) VisitUnaryCriteria ¶
func (v *IndexSelectVisitor) VisitUnaryCriteria(c *query.UnaryCriteria) interface{}
type NotFlattenVisitor ¶
type NotFlattenVisitor struct { }
func (*NotFlattenVisitor) VisitBinaryCriteria ¶
func (v *NotFlattenVisitor) VisitBinaryCriteria(c *query.BinaryCriteria) interface{}
func (*NotFlattenVisitor) VisitNotCriteria ¶
func (v *NotFlattenVisitor) VisitNotCriteria(c *query.NotCriteria) interface{}
func (*NotFlattenVisitor) VisitUnaryCriteria ¶
func (v *NotFlattenVisitor) VisitUnaryCriteria(c *query.UnaryCriteria) interface{}
type Option ¶
Option is a function that takes a config struct and modifies it
func InMemoryMode ¶
InMemoryMode allows to enable/disable in-memory mode.
func WithGCReclaimInterval ¶
WithGCReclaimInterval allow to configure how often we reclaim disk space
type StorageEngine ¶
type StorageEngine interface { Open(path string, c *Config) error Close() error CreateCollection(name string) error ListCollections() ([]string, error) DropCollection(name string) error HasCollection(name string) (bool, error) Count(q *query.Query) (int, error) FindAll(q *query.Query) ([]*d.Document, error) FindById(collectionName string, id string) (*d.Document, error) UpdateById(collectionName string, docId string, updater func(doc *d.Document) *d.Document) error DeleteById(collectionName string, id string) error IterateDocs(q *query.Query, consumer docConsumer) error Insert(collection string, docs ...*d.Document) error Update(q *query.Query, updater func(doc *d.Document) *d.Document) error Delete(q *query.Query) error CreateIndex(collection, field string) error DropIndex(collection, field string) error HasIndex(collection, field string) (bool, error) ListIndexes(collection string) ([]index.IndexInfo, error) }
StorageEngine represents the persistance layer and abstracts how collections are stored.