yamgo

package module
v0.0.0-...-35ea870 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 12 Imported by: 0

README

YAMGO [![GoDoc][doc-img]][doc]

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/wezard-it/yamgo

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

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

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

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

func NewModel

func NewModel(collectionName string) Model

func (*Model) Aggregate

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

func (*Model) CountDocuments

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

func (*Model) Find

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

func (*Model) FindAndPopulate

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

func (*Model) FindByID

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

func (*Model) FindByObjectID

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

func (*Model) FindOne

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

func (*Model) FindOneAndPopulate

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

func (*Model) FindWithOptions

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

func (*Model) InsertMany

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

func (*Model) InsertOne

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

func (*Model) PaginatedAggregate

func (mf *Model) PaginatedAggregate(example *[]bson.Raw, prevCursor string, nextCursor string, limit int64, pipeline ...interface{}) (Page, error)

func (*Model) PaginatedFind

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