Documentation ¶
Index ¶
- Variables
- func NewObjectId() string
- 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) CreateCollectionByQuery(name string, q *query.Query) 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) IterateDocs(q *query.Query, consumer docConsumer) error
- func (db *DB) ListCollections() ([]string, error)
- func (db *DB) ListIndexes(collection string) ([]index.Info, error)
- func (db *DB) ReplaceById(collection, docId string, doc *d.Document) error
- func (db *DB) Save(collectionName string, data interface{}) error
- func (db *DB) Update(q *query.Query, updateMap map[string]interface{}) error
- func (db *DB) UpdateById(collectionName string, docId string, updater func(doc *d.Document) *d.Document) error
- func (db *DB) UpdateFunc(q *query.Query, updateFunc func(doc *d.Document) *d.Document) error
- type FieldRangeVisitor
- type IndexSelectVisitor
- type NotFlattenVisitor
Constants ¶
This section is empty.
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") ErrDocumentNotExist = errors.New("no such document") ErrDuplicateKey = errors.New("duplicate key") )
Collection creation errors
Functions ¶
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 OpenWithStore ¶
OpenWithStore opens a new clover database using the provided store.
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) CreateCollectionByQuery ¶
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 index, 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 provided 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 index 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) Save ¶
Save or update a document, If you pass in a custom struct instead of a Document object, it is recommended to specify the _id field using struct tags.
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 ¶
func (db *DB) UpdateById(collectionName string, docId string, updater func(doc *d.Document) *d.Document) error
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{}