当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.ExecuteMGO方法代码示例

本文整理汇总了Golang中github.com/coralproject/shelf/pkg/db.DB.ExecuteMGO方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.ExecuteMGO方法的具体用法?Golang DB.ExecuteMGO怎么用?Golang DB.ExecuteMGO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coralproject/shelf/pkg/db.DB的用法示例。


在下文中一共展示了DB.ExecuteMGO方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateUser

// CreateUser creates a new user resource
func CreateUser(context interface{}, db *db.DB, user *User) error {
	log.Dev(context, "CreateUser", "Started : User: ", user)

	/* This error condition should be performed by DB indexes
	dbUser, err := GetUserByUserName(context, db, user.UserName)
	if dbUser != nil {
		log.Error(context, "CreateUser", err, "User exists")
		return "CreateUser: user with same UserName already exists"
	}
	*/

	// set defaults, may want to move this to a factory method on the User struct
	if user.UserID == "" {
		user.UserID = uuid.New()
	}
	user.MemberSince = time.Now()

	f := func(col *mgo.Collection) error {
		log.Dev(context, "CreateUser", "MGO: db.%s.insert()", userCollection)
		return col.Insert(user)
	}

	// Write the user to mongo
	if err := db.ExecuteMGO(context, userCollection, f); err != nil {
		log.Error(context, "CreateUser", err, "Completed")
		return err
	}

	log.Dev(context, "CreateUser", "Completed")
	return nil
}
开发者ID:coralproject,项目名称:sponge,代码行数:32,代码来源:comment.go

示例2: removeUser

// removeUser is used to clear out all the test user from the collection.
func removeUser(db *db.DB, UserID string) error {
	f := func(c *mgo.Collection) error {
		q := bson.M{"user_id": UserID}
		return c.Remove(q)
	}

	if err := db.ExecuteMGO(tests.Context, "users", f); err != nil {
		return err
	}

	return nil
}
开发者ID:coralproject,项目名称:sponge,代码行数:13,代码来源:comment_test.go

示例3: removeComment

// removeComment is used to clear out all the test user from the collection.
func removeComment(db *db.DB, CommentID string) error {
	f := func(c *mgo.Collection) error {
		q := bson.M{"comment_id": CommentID}
		return c.Remove(q)
	}

	if err := db.ExecuteMGO(tests.Context, "comments", f); err != nil {
		return err
	}

	return nil
}
开发者ID:coralproject,项目名称:sponge,代码行数:13,代码来源:comment_test.go

示例4: GetUserByID

// GetUserByID retrieves an individual user by ID
func GetUserByID(context interface{}, db *db.DB, id string) (*User, error) {
	log.Dev(context, "GetUserById", "Started : Id[%s]", id)

	var user User
	f := func(c *mgo.Collection) error {
		q := bson.M{"_id": id}
		log.Dev(context, "GetUserById", "MGO : db.%s.findOne(%s)", userCollection, mongo.Query(q))
		return c.Find(q).One(&user)
	}

	if err := db.ExecuteMGO(context, userCollection, f); err != nil {
		log.Error(context, "GetUserById", err, "Completed")
		return nil, err
	}

	log.Dev(context, "GetUserById", "Completed")
	return &user, nil
}
开发者ID:coralproject,项目名称:sponge,代码行数:19,代码来源:comment.go

示例5: GetUserByUserName

// GetUserByUserName retrieves an individual user by email
func GetUserByUserName(context interface{}, db *db.DB, userName string) (*User, error) {
	log.Dev(context, "GetUserByUserName", "Started : User[%s]", userName)

	userName = strings.ToLower(userName)

	var user User
	f := func(c *mgo.Collection) error {
		q := bson.M{"user_name": userName}
		log.Dev(context, "GetUserByUserName", "MGO : db.%s.findOne(%s)", userCollection, mongo.Query(q))
		return c.Find(q).One(&user)
	}

	if err := db.ExecuteMGO(context, userCollection, f); err != nil {
		log.Error(context, "GetUserByUserName", err, "Completed")
		return nil, err
	}

	log.Dev(context, "GetUserByUserName", "Completed")
	return &user, nil
}
开发者ID:coralproject,项目名称:sponge,代码行数:21,代码来源:comment.go

示例6: CreateComment

// CreateComment adds a new comment in the database.
func CreateComment(context interface{}, db *db.DB, com *Comment) error {
	if com.CommentID == "" {
		com.CommentID = uuid.New()
	}
	com.DateCreated = time.Now()
	com.Status = "New"

	f := func(col *mgo.Collection) error {
		log.Dev(context, "CreateComment", "MGO: db.%s.insert()", commentCollection)
		return col.Insert(com)
	}

	if err := db.ExecuteMGO(context, commentCollection, f); err != nil {
		log.Error(context, "CreateComment", err, "Completed")
		return err
	}

	log.Dev(context, "CreateComment", "Completed")

	return nil
}
开发者ID:coralproject,项目名称:sponge,代码行数:22,代码来源:comment.go


注:本文中的github.com/coralproject/shelf/pkg/db.DB.ExecuteMGO方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。