mingodb

package module
v0.0.0-...-6f3902b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 7 Imported by: 0

README

MingoDB

created by Austin Poor

An embedded document DB written in pure Go, inspired by MongoDB and based on BoltDB.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOpeningDatabase = errors.New("unable to open the database")
	ErrEmptyBucketName = errors.New("bucket name cannot be empty")
	ErrCreatingBucket  = errors.New("unable to create bucket")
	ErrInvalidType     = errors.New("invalid type, expected struct/map")
)

Functions

This section is empty.

Types

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

Collection represents a collection of MingoDB documents.

func (*Collection) CountDocuments

func (c *Collection) CountDocuments(filter interface{}) (int, error)

CountDocuments returns the number of documents that match the filter.

func (*Collection) Database

func (c *Collection) Database() *Database

Database returns a pointer to the collection's parent database.

func (*Collection) DeleteMany

func (c *Collection) DeleteMany(filter []interface{}) (*DeleteResult, error)

DeleteMany inserts multiple documents into the collection.

func (*Collection) DeleteOne

func (c *Collection) DeleteOne(filter interface{}) (*DeleteResult, error)

DeleteOne deletes a single document into the collection based on the filter

func (*Collection) Drop

func (c *Collection) Drop() error

Drop deletes the collection.

func (*Collection) Find

func (c *Collection) Find(filter interface{}) (MultiResult, interface{}, error)

Find returns (up to) multiple documents from the collection based on the filter provided.

func (*Collection) FindOne

func (c *Collection) FindOne(filter interface{}, result interface{}) (*SingleResult, error)

FindOne returns the first document (if any) that matches the filter.

func (*Collection) GetByID

func (c *Collection) GetByID(id interface{}) (interface{}, error)

func (*Collection) InsertMany

func (c *Collection) InsertMany(docs []interface{}) ([]InsertID, error)

InsertMany inserts multiple documents into the collection. Returns an array of the inserted documents' _id values (If generated by the DB, will be of type primitive.ObjectID).

func (*Collection) InsertOne

func (c *Collection) InsertOne(doc interface{}) (InsertID, error)

InsertOne inserts a single document into the collection. Returns the _id of the inserted document (if generated by the DB, will be of type primitive.ObjectID).

Expects doc to be either a struct or a map[string]interface{}. Note that if doc is a struct, only expored fields will be stored.

func (*Collection) Name

func (c *Collection) Name() string

Name returns the name of the collection.

func (*Collection) UpdateMany

func (c *Collection) UpdateMany(docs []interface{}) (*UpdateResult, error)

UpdateMany

func (*Collection) UpdateOne

func (c *Collection) UpdateOne(doc interface{}) (*UpdateResult, error)

UpdateOne

type Database

type Database struct {
	Path string
	// contains filtered or unexported fields
}

Database represents a MingoDB database connection.

func Open

func Open(path string) (*Database, error)

Open creates a new database connection at the path specified. If the path does not exist, it will be created.

func (*Database) Close

func (db *Database) Close() error

Close closes the database connection and cleans up any resources. Will block until all pending operations have completed.

func (*Database) Collection

func (db *Database) Collection(name string) (*Collection, error)

Collection returns a DB collection object with the specified name. If the collection does not exist, it will be created.

func (*Database) CollectionMust

func (db *Database) CollectionMust(name string) *Collection

CollectionMust returns a DB collection object with the specified name. If the collection does not exist, it will be created. Note: This function wraps Collection() and panics if an error is returned.

type DeleteResult

type DeleteResult struct {
	DeleteCount int // Number of rows deleted
}

type InsertID

type InsertID interface{}

type MultiResult

type MultiResult struct {
	//data []byte
	ResultCount int // Number of returned results
}

type SingleResult

type SingleResult struct {
	// contains filtered or unexported fields
}

type UpdateResult

type UpdateResult struct {
	UpdateCount int // Number of rows updated
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL