mgorm

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

README

mgorm

Another Mongodb Library with ORM. Inspired by 'gorm' and 'pymongo' and based on 'globalsign/mgo'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRawSession added in v1.1.1

func GetRawSession(alias string) *mgo.Session

GetSession return original session for specified server alias

func GetSession

func GetSession(alias string) *mgo.Session

GetSession return an copy of original session for specified server alias

func Init

func Init(urls map[string]string) error

Init load configs: usls: <mongo-alias:url>

func InitWithInfo added in v1.1.0

func InitWithInfo(infos map[string]*mgo.DialInfo) error

func IsErrDuplicate added in v1.0.1

func IsErrDuplicate(err error) bool

IsErrDuplicate check if duplicate-key error

func IsErrNotFound added in v1.0.1

func IsErrNotFound(err error) bool

IsErrNotFound check if not-found error

Types

type CloseFunc

type CloseFunc func()

CloseFunc use for close session

type FindOpt

type FindOpt func(*findOpts)

FindOpt is option for find

func Limit

func Limit(limit int) FindOpt

Limit for result

func Skip

func Skip(skip int) FindOpt

Skip on cursor

func Sort

func Sort(fields ...string) FindOpt

Sort result

type Iter

type Iter struct {
	*mgo.Iter
	// contains filtered or unexported fields
}

Iter wrap original iter, add close function

func (*Iter) Close

func (it *Iter) Close() error

Close ...

type Model

type Model struct {
	MongoAlias     string
	DBName         string
	CollectionName string
}

Model for collection

func NewModel added in v1.0.1

func NewModel(alias, db, collection string) Model

NewModel make new model

func (*Model) C

func (m *Model) C() (*mgo.Collection, CloseFunc)

C get original colletion for Model

func (*Model) Count

func (m *Model) Count(selector interface{}) (int, error)

Count documents matching selector

func (*Model) CreateIndex

func (m *Model) CreateIndex(index mgo.Index) error

CreateIndex for Collection

func (*Model) Delete

func (m *Model) Delete(selector bson.M) error

Delete document matching selector

func (*Model) DeleteAll

func (m *Model) DeleteAll(selector bson.M) error

DeleteAll find all document matching selector and delete them

func (*Model) FindAll

func (m *Model) FindAll(result, selector interface{}, opts ...FindOpt) error

FindAll documents matching selector

func (*Model) FindID

func (m *Model) FindID(result, id interface{}) error

FindID find document by id

func (*Model) FindOne

func (m *Model) FindOne(result, selector interface{}) error

FindOne document by selector

func (*Model) GetIter

func (m *Model) GetIter(selector interface{}) *Iter

GetIter make an iter for selector

func (*Model) Insert added in v1.0.1

func (m *Model) Insert(docs ...interface{}) error

Insert documents

func (*Model) Update

func (m *Model) Update(selector, update interface{}, opts ...UpdateOpt) error

Update document matching selector

func (*Model) UpdateAll

func (m *Model) UpdateAll(selector, update interface{}) error

UpdateAll finds all documents matching the provided selector document and update them

func (*Model) UpdateID

func (m *Model) UpdateID(id, update interface{}, opts ...UpdateOpt) error

UpdateID updata document matching ID

type OID added in v1.2.0

type OID bson.ObjectId

OID fit for json, bson and msgpack

func ParseOIDFromString added in v1.2.0

func ParseOIDFromString(s string) (OID, error)

ParseOIDFromString parse oid from string

func (*OID) DecodeMsgpack added in v1.2.1

func (o *OID) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack decode oid from Msgpack

func (*OID) EncodeMsgpack added in v1.2.1

func (o *OID) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack encode oid to Msgpack

func (OID) GetBSON added in v1.2.2

func (o OID) GetBSON() (interface{}, error)

GetBSON for saving to mongodb

func (OID) MarshalJSON added in v1.2.0

func (o OID) MarshalJSON() ([]byte, error)

MarshalJSON marshal oid to json

func (OID) ObjectID added in v1.2.0

func (o OID) ObjectID() bson.ObjectId

ObjectID value of OID

func (*OID) SetBSON added in v1.2.2

func (o *OID) SetBSON(raw bson.Raw) error

SetBSON for getting from mongodb

func (OID) String added in v1.2.0

func (o OID) String() string

String of OID

func (*OID) UnmarshalJSON added in v1.2.0

func (o *OID) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshal oid from json

type UpdateOpt

type UpdateOpt func(*updateOpts)

UpdateOpt is option for update

func Upsert

func Upsert() UpdateOpt

Upsert option

Jump to

Keyboard shortcuts

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