yamgo

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 11 Imported by: 0

README

YAMGO GoDoc

Yamgo is a MongoDB object modeling tool designed to developers working with the native Mongo Go Driver. Yamgo supports both promises and callbacks.

Installation

go get -u github.com/nocfer/yamgo

Documentation

You can find the documentation at the website https://pkg.go.dev/github.com/nocfer/yamgo

Support

Contributors

Pull requests are always welcome!

This is a personal project and also my first approach to golang in general, feel free to help me make this module better with your contribution.

Please base your pull requests against the master branch.

Documentation

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	ShortTimeout  time.Duration = 2
	MediumTimeout time.Duration = 5
	LongTimeout   time.Duration = 10
)

Variables

This section is empty.

Functions

func BuildLookupStage added in v0.0.8

func BuildLookupStage(populate PopulateOptions) []bson.D

func BuildQueries

func BuildQueries(p PaginationFindParams) (queries []bson.M, sort bson.D, err error)

func Connect

func Connect(params ConnectionParams)

It connects to the database.

func Disconnect added in v0.0.5

func Disconnect() error

func GenerateCursorQuery

func GenerateCursorQuery(shouldSecondarySortOnID bool, paginatedField string, comparisonOp string, cursorFieldValues []interface{}) (map[string]interface{}, error)

func GetCollection

func GetCollection(collectionName string) *mongo.Collection

func ToObjectID

func ToObjectID(hex string) primitive.ObjectID

Types

type ConnectionParams

type ConnectionParams struct {
	ConnectionUrl string
	DbName        string
}

type CursorError

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

func (*CursorError) Error

func (e *CursorError) Error() string

type Model added in v0.0.4

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

func NewModel

func NewModel(collectionName string) Model

func (*Model) Aggregate added in v0.0.6

func (mf *Model) Aggregate(pipeline mongo.Pipeline, results interface{}) error

func (*Model) CountDocuments added in v0.0.4

func (mf *Model) CountDocuments(filter bson.M) (int, error)

func (*Model) Find added in v0.0.4

func (mf *Model) Find(filter bson.M, results interface{}) error

func (*Model) FindAndPopulate added in v0.0.4

func (mf *Model) FindAndPopulate(filter bson.M, option options.FindOptions, populate []PopulateOptions, results interface{}) error

func (*Model) FindByID added in v0.0.4

func (mf *Model) FindByID(id string, result interface{}) (err error)

func (*Model) FindByObjectID added in v0.0.4

func (mf *Model) FindByObjectID(objectID primitive.ObjectID, result interface{}) (err error)

func (*Model) FindOne added in v0.0.4

func (mf *Model) FindOne(filter bson.M, result interface{}) (err error)

func (*Model) FindOneAndPopulate added in v0.0.4

func (mf *Model) FindOneAndPopulate(filter bson.M, findOptions options.FindOptions, populate []PopulateOptions, result interface{}) error

func (*Model) FindWithOptions added in v0.0.4

func (mf *Model) FindWithOptions(filter bson.M, option options.FindOptions, results interface{}) error

func (*Model) InsertMany added in v0.0.4

func (mf *Model) InsertMany(records []interface{}) (res *mongo.InsertManyResult, err error)

func (*Model) InsertOne added in v0.0.4

func (mf *Model) InsertOne(record interface{}) (res *mongo.InsertOneResult, err error)

func (*Model) PaginatedFind added in v0.0.4

func (mf *Model) PaginatedFind(params PaginationFindParams, results interface{}) (Page, error)

type Mongo

type Mongo struct {
	Database *mongo.Database
	Err      error
	// contains filtered or unexported fields
}

func GetDB

func GetDB() Mongo

type Page

type Page struct {
	Previous    string `json:"previous,omitempty"`
	Next        string `json:"next,omitempty"`
	HasPrevious bool   `json:"has_previous"`
	HasNext     bool   `json:"has_next"`
	Count       int    `json:"count,omitempty"`
}

type PaginationFindParams

type PaginationFindParams struct {
	Query          primitive.M        `form:"query"`
	Limit          int64              `form:"limit" binding:"required"`
	SortAscending  bool               `form:"sort_ascending"`
	PaginatedField string             `form:"paginated_field"`
	Collation      *options.Collation `form:"collation"`
	Next           string             `form:"next"`
	Previous       string             `form:"previous"`
	CountTotal     bool               `form:"count_total"`
	Hint           interface{}        `form:"hint"`
	Projection     string             `form:"projection"`
	Expansion      []PopulateOptions
}

type PopulateOptions

type PopulateOptions struct {
	Collection string
	LocalField string
	As         string
	Projection []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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