odm

package module
v0.0.0-...-2a45f3f Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MongodbURI string

Functions

This section is empty.

Types

type DocumentBase

type DocumentBase struct {
	ID bson.ObjectId `json:"_id" bson:"_id"`
}

DocumentBase implements all the methods to the IEntity interface

func (*DocumentBase) GetID

func (doc *DocumentBase) GetID() bson.ObjectId

GetID returns the id of the document

func (*DocumentBase) SetID

func (doc *DocumentBase) SetID(ID bson.ObjectId)

SetID sets the ID field of the document

type IEntity

type IEntity interface {
	SetID(bson.ObjectId)
	GetID() bson.ObjectId
}

IEntity defines all the methods to be used on the documents when saved and queried on the db

type PaginationInfo

type PaginationInfo struct {
	CurrentPage    int
	NumPages       int
	RecordsPerPage int
	NumRecords     int
}

type Query

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

func (*Query) All

func (q *Query) All(docs interface{}) error

func (*Query) Limit

func (q *Query) Limit(n int) *Query

func (*Query) Next

func (q *Query) Next(doc IEntity) bool

func (*Query) Skip

func (q *Query) Skip(n int) *Query

func (*Query) Sort

func (q *Query) Sort(fields ...string) *Query

type Repository

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

func NewRepository

func NewRepository(database, collection string) *Repository

func (*Repository) Count

func (r *Repository) Count(query bson.M) (int, error)

func (*Repository) Delete

func (r *Repository) Delete(doc IEntity) error

func (*Repository) Find

func (r *Repository) Find(query bson.M) (*Query, error)

func (*Repository) FindOne

func (r *Repository) FindOne(query bson.M, doc IEntity) error

func (*Repository) GetByID

func (r *Repository) GetByID(ID bson.ObjectId, doc IEntity) error

func (*Repository) Paginate

func (r *Repository) Paginate(query bson.M, recordsPerPage, page int) (*Query, *PaginationInfo, error)

func (*Repository) Save

func (r *Repository) Save(doc IEntity) error

Jump to

Keyboard shortcuts

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