database

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewModelManager

func NewModelManager(url, dbname string)

Types

type Model

type Model struct {
	Id        bson.ObjectId `json:"id" bson:"_id,omitempty"`
	AppID     bson.ObjectId `json:"app_id" bson:"app_id,omitempty"`
	CreatedAt int64         `json:"created_at" bson:"created_at"`
	UpdatedAt int64         `json:"updated_at" bson:"updated_at"`
	Invalid   bool          `json:"invalid" bson:"invalid"`
	InvalidAt int64         `json:"invalid_at" bson:"invalid_at"`
}

type ModelManager

type ModelManager struct {
}

func (*ModelManager) C

func (this *ModelManager) C(name string) *mgo.Collection

func (*ModelManager) Count

func (this *ModelManager) Count(cName string, selector bson.M) (count int, err error)

func (*ModelManager) DropCollection

func (this *ModelManager) DropCollection(cName string) (err error)

func (*ModelManager) FindAll

func (this *ModelManager) FindAll(cName string, query bson.M, results interface{}) (err error)

func (*ModelManager) FindOne

func (this *ModelManager) FindOne(cName string, query bson.M, result interface{}) (err error)

func (*ModelManager) GetMongoDB

func (this *ModelManager) GetMongoDB() *MongoDB

func (*ModelManager) Insert

func (this *ModelManager) Insert(cName string, model interface{}) (err error)

func (*ModelManager) Remove

func (this *ModelManager) Remove(cName string, selector bson.M) (err error)

func (*ModelManager) RemoveWithId

func (this *ModelManager) RemoveWithId(cName string, id bson.ObjectId) (err error)

func (*ModelManager) Session

func (this *ModelManager) Session(callback func(s *mgo.Session))

func (*ModelManager) Update

func (this *ModelManager) Update(cName string, selector bson.M, update interface{}) (err error)

func (*ModelManager) UpdateAll

func (this *ModelManager) UpdateAll(cName string, selector bson.M, update interface{}) (info *mgo.ChangeInfo, err error)

func (*ModelManager) UpdateWithId

func (this *ModelManager) UpdateWithId(cName string, id bson.ObjectId, update interface{}) (err error)

type MongoDB

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

func NewMongoDB

func NewMongoDB(url, dbName string) *MongoDB

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database[?options]]

func (*MongoDB) C

func (this *MongoDB) C(name string) *mgo.Collection

从主 Session 获取一个集合

func (*MongoDB) MainSession

func (this *MongoDB) MainSession() *mgo.Session

func (*MongoDB) NewSession

func (this *MongoDB) NewSession() *mgo.Session

需要调用者自行 Session.Close()

type MongoDBClient

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

func (MongoDBClient) Close

func (this MongoDBClient) Close()

Jump to

Keyboard shortcuts

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