Documentation
¶
Index ¶
- Variables
- type Collection
- func (c *Collection) CreateIndex(ctx context.Context, index IndexModel) error
- func (c *Collection) CreateManyIndexes(ctx context.Context, indexes []IndexModel) error
- func (c *Collection) Delete(filter map[string]any) DeleteManyResult
- func (c *Collection) DeleteByID(id any) DeleteOneResult
- func (c *Collection) DeleteOne(filter map[string]any) DeleteOneResult
- func (c *Collection) Find(filter map[string]any, opts ...*options.FindOptions) FindResult
- func (c *Collection) FindByID(id any) FindOneResult
- func (c *Collection) FindOne(filter map[string]any) FindOneResult
- func (c *Collection) Insert(docs any) InsertManyResult
- func (c *Collection) InsertOne(doc any) InsertOneResult
- func (c *Collection) Update(filter map[string]any, docs any, opts ...*options.UpdateOptions) UpdateManyResult
- func (c *Collection) UpdateOne(filter map[string]any, doc any, opts ...*options.UpdateOptions) UpdateOneResult
- type CollectionMetadata
- type Database
- type DatabaseMetadata
- type DeleteManyResult
- type DeleteOneResult
- type FindOneResult
- type FindResult
- type IndexField
- type IndexManager
- type IndexModel
- type IndexOptions
- type InsertManyResult
- type InsertOneResult
- type QueryPlan
- type QueryPlanner
- type UpdateManyResult
- type UpdateOneResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingFieldForIndex is returned when a field is missing for an index. ErrMissingFieldForIndex = errors.New("missing field for index") // ErrEmptyIndexFields is returned when an index has no fields. ErrEmptyIndexFields = errors.New("empty index fields") // ErrDuplicateIndexField is returned when a duplicate index field is found. ErrDuplicateIndexField = errors.New("duplicate index field") // ErrUniqueIndexViolation is returned when a unique index is violated. ErrUniqueIndexViolation = errors.New("unique index violation") // ErrIndexAlreadyExists is returned when an index already exists. ErrIndexAlreadyExists = errors.New("index already exists") // ErrInvalidValueType is returned when an invalid value type is used. ErrInvalidValueType = errors.New("invalid value type") // ErrMapTypeConversionFailed is returned when a map type conversion fails. ErrMapTypeConversionFailed = errors.New("map type conversion failed") // ErrUnsupportedTypeForMapConversion is returned when an unsupported type is used for map conversion. ErrUnsupportedTypeForMapConversion = errors.New("unsupported type for map conversion") // ErrMustBePointer is returned when a value is not a pointer. ErrMustBePointer = errors.New("must be a pointer") // ErrDocumentNotFound is returned when a document is not found. ErrDocumentNotFound = errors.New("document not found") // ErrDocumentIsNil is returned when a document is nil. ErrDocumentIsNil = errors.New("document is nil") // ErrDocumentSliceIsNil is returned when a document slice is nil. ErrDocumentSliceIsNil = errors.New("document slice is nil") // ErrDocumentSlicePointerIsNil is returned when a document slice pointer is nil. ErrDocumentSlicePointerIsNil = errors.New("document slice pointer is nil") // ErrDocumentSliceEmpty is returned when a document slice is empty. ErrDocumentSliceEmpty = errors.New("document slice is empty") // ErrDocumentSliceTypeInvalid is returned when a document slice type is invalid. ErrDocumentSliceTypeInvalid = errors.New("document slice type is invalid") // ErrDocumentSliceElementTypeInvalid is returned when a document slice element type is invalid. ErrDocumentSliceElementTypeInvalid = errors.New("document slice element type is invalid") // ErrDocumentPointerIsNil is returned when a document pointer is nil. ErrDocumentPointerIsNil = errors.New("document pointer is nil") // ErrDocumentTypeInvalid is returned when a document type is invalid. ErrDocumentTypeInvalid = errors.New("document type is invalid") // ErrDocumentIDNotFound is returned when a document ID is not found. ErrDocumentIDNotFound = errors.New("document ID not found") // ErrDocumentIDNoEditable is returned when a document ID is not editable. ErrDocumentIDNoEditable = errors.New("document ID no editable") )
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
IndexManager *IndexManager
// contains filtered or unexported fields
}
Collection is a collection of documents.
func (*Collection) CreateIndex ¶
func (c *Collection) CreateIndex(ctx context.Context, index IndexModel) error
CreateIndex crea un nuevo índice en la colección.
func (*Collection) CreateManyIndexes ¶
func (c *Collection) CreateManyIndexes(ctx context.Context, indexes []IndexModel) error
CreateManyIndexes crea múltiples índices en la colección.
func (*Collection) Delete ¶
func (c *Collection) Delete(filter map[string]any) DeleteManyResult
Delete deletes multiple documents by a filter.
func (*Collection) DeleteByID ¶
func (c *Collection) DeleteByID(id any) DeleteOneResult
DeleteByID deletes a single document by its ID.
func (*Collection) DeleteOne ¶
func (c *Collection) DeleteOne(filter map[string]any) DeleteOneResult
DeleteOne deletes a single document by a filter.
func (*Collection) Find ¶
func (c *Collection) Find( filter map[string]any, opts ...*options.FindOptions, ) FindResult
Find finds documents by a filter.
func (*Collection) FindByID ¶
func (c *Collection) FindByID(id any) FindOneResult
FindByID finds a document by its ID.
func (*Collection) FindOne ¶
func (c *Collection) FindOne( filter map[string]any, ) FindOneResult
FindOne finds a single document by a filter.
func (*Collection) Insert ¶
func (c *Collection) Insert(docs any) InsertManyResult
Insert inserts multiple documents into the collection.
func (*Collection) InsertOne ¶
func (c *Collection) InsertOne(doc any) InsertOneResult
InsertOne inserts a single document into the collection.
func (*Collection) Update ¶
func (c *Collection) Update( filter map[string]any, docs any, opts ...*options.UpdateOptions, ) UpdateManyResult
Update updates multiple documents by a filter.
func (*Collection) UpdateOne ¶
func (c *Collection) UpdateOne( filter map[string]any, doc any, opts ...*options.UpdateOptions, ) UpdateOneResult
UpdateOne updates a single document by a filter.
type CollectionMetadata ¶
type CollectionMetadata struct {
Name string `json:"name"`
Indexes []IndexModel `json:"indexes"`
DocumentCount int64 `json:"document_count"`
}
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database es una base de datos.
func NewDatabase ¶
NewDatabase crea una nueva instancia de Database.
func (*Database) Collection ¶
func (db *Database) Collection(name string) (*Collection, error)
Collection devuelve una instancia de Collection para la base de datos
type DatabaseMetadata ¶
type DatabaseMetadata struct {
Name string `json:"name"`
}
type DeleteManyResult ¶
DeleteManyResult es el resultado de una eliminación de múltiples documentos.
type DeleteOneResult ¶
DeleteOneResult es el resultado de una eliminación de un documento.
type FindOneResult ¶
type FindOneResult struct {
IndexUsed *IndexModel
Err error
// contains filtered or unexported fields
}
FindOneResult es el resultado de una consulta de un documento.
func (*FindOneResult) Document ¶
func (r *FindOneResult) Document() map[string]any
Document returns the document of the find one result.
func (*FindOneResult) Unmarshal ¶
func (r *FindOneResult) Unmarshal(result any) error
Unmarshal unmarshals the result into a struct.
type FindResult ¶
type FindResult struct {
TotalCount int64
IndexUsed *IndexModel
Err error
// contains filtered or unexported fields
}
FindResult es el resultado de una consulta.
func (*FindResult) Unmarshal ¶
func (r *FindResult) Unmarshal(results any) error
Unmarshal unmarshals the results into a slice of the given type.
type IndexField ¶
IndexField represents a field in an index.
type IndexManager ¶
type IndexManager struct {
// contains filtered or unexported fields
}
IndexManager is a manager for indexes.
func (*IndexManager) CreateMany ¶
func (m *IndexManager) CreateMany(ctx context.Context, indexes []IndexModel) error
CreateMany creates many indexes.
func (*IndexManager) List ¶
func (m *IndexManager) List() []IndexModel
List returns all the indexes for the collection.
type IndexModel ¶
type IndexModel struct {
Fields []IndexField `json:"fields"`
Options IndexOptions `json:"options"`
}
IndexModel represents a model for an index.
func (*IndexModel) AddField ¶
func (index *IndexModel) AddField(name string, order int) *IndexModel
AddField adds a field to the index model.
func (*IndexModel) SetName ¶
func (index *IndexModel) SetName(name string) *IndexModel
SetOptions sets the options for the index model.
func (*IndexModel) SetUnique ¶
func (index *IndexModel) SetUnique(unique bool) *IndexModel
SetUnique sets the unique flag of the index model.
func (*IndexModel) Value ¶
func (index *IndexModel) Value() IndexModel
Value returns the index model.
type IndexOptions ¶
type IndexOptions struct {
Name string `json:"name"`
Unique bool `json:"unique"`
Autogenerated bool `json:"autogenerated"`
}
IndexOptions represents the options for an index.
func NewIndexOptions ¶
func NewIndexOptions() *IndexOptions
NewIndexOptions creates a new index options.
func (*IndexOptions) SetName ¶
func (o *IndexOptions) SetName(name string) *IndexOptions
SetName sets the name of the index options.
func (*IndexOptions) SetUnique ¶
func (o *IndexOptions) SetUnique(unique bool) *IndexOptions
SetUnique sets the unique flag of the index options.
func (*IndexOptions) Value ¶
func (o *IndexOptions) Value() IndexOptions
Value returns the index options.
type InsertManyResult ¶
InsertManyResult es el resultado de una inserción de múltiples documentos.
type InsertOneResult ¶
InsertOneResult es el resultado de una inserción.
type QueryPlan ¶
type QueryPlan struct {
IndexUsed *IndexModel
IndexFilter map[string]any
UsedForSort bool
IsExact bool
}
QueryPlan is the plan for a query.
type QueryPlanner ¶
type QueryPlanner struct {
// contains filtered or unexported fields
}
QueryPlanner is the planner for a query.
func NewQueryPlanner ¶
func NewQueryPlanner(indexes []IndexModel) *QueryPlanner
NewQueryPlanner creates a new QueryPlanner.
type UpdateManyResult ¶
UpdateManyResult es el resultado de una actualización de múltiples documentos.
type UpdateOneResult ¶
UpdateOneResult es el resultado de una actualización de un documento.