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


Golang DbMap.Get方法代码示例

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


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

示例1: GetNew

func GetNew(db *gorp.DbMap, id int64) (New, error) {
	obj, err := db.Get(New{}, id)
	if err != nil {
		return New{}, err
	}
	if obj == nil {
		return New{}, errors.New("New not found")
	}
	n := obj.(*New)
	return *n, nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:11,代码来源:db.go

示例2: GetProduct

func GetProduct(db *gorp.DbMap, productid int64) (StoreProduct, error) {
	var sp = StoreProduct{}
	obj, err := db.Get(StoreProduct{}, productid)
	if err != nil {
		return sp, err
	}
	if obj == nil {
		return sp, errors.New("Product not found")
	}
	sp = *obj.(*StoreProduct)
	return sp, nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:12,代码来源:db.go

示例3: Get

func Get(db *gorp.DbMap, id int64) (User, error) {
	var user User
	obj, err := db.Get(User{}, id)
	if err != nil {
		return user, err
	}
	if obj == nil {
		return user, errors.New("User not found")
	}
	user = *obj.(*User)
	return user, nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:12,代码来源:db.go

示例4: GetDelivery

func GetDelivery(db *gorp.DbMap, deliveryid int64) (OrderDelivery, error) {
	var dlv OrderDelivery
	obj, err := db.Get(OrderDelivery{}, deliveryid)
	if err != nil {
		return dlv, err
	}
	if obj == nil {
		return dlv, errors.New("Delivery not found")
	}
	dlv = *obj.(*OrderDelivery)
	return dlv, nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:12,代码来源:db.go

示例5: ProductsShow

func ProductsShow(db *gorp.DbMap, params martini.Params, render render.Render) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		panic(err)
	}
	product, err := db.Get(models.Product{}, id)

	if err == nil {
		render.JSON(200, product)
	} else {
		render.JSON(404, map[string]string{"error": err.Error()})
	}
}
开发者ID:joiggama,项目名称:martini-example,代码行数:13,代码来源:products.go

示例6: GetUsers

func GetUsers(db *gorp.DbMap, ids []int64) ([]User, error) {
	var users []User
	for _, id := range ids {
		obj, err := db.Get(User{}, id)
		if err != nil {
			return users, err
		}
		if obj == nil {
			return users, errors.New("User not found")
		}
		user := *obj.(*User)
		users = append(users, user)
	}
	return users, nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:15,代码来源:db.go

示例7: GetGame

func (gs *GameServiceImpl) GetGame(db *gorp.DbMap, gameId string, playerId int) (*Game, *Player, error) {
	obj, err := db.Get(Player{}, playerId)
	if err != nil {
		return nil, nil, err
	}
	player := obj.(*Player)

	// get the game from the db to load the state, other info
	g, err := db.Get(Game{}, gameId)
	if err != nil {
		return nil, nil, err
	}
	game := g.(*Game)
	return game, player, nil
}
开发者ID:jakecoffman,项目名称:game-server,代码行数:15,代码来源:services.go

示例8: GetTask

func GetTask(r render.Render, params martini.Params, db *gorp.DbMap) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		r.JSON(400, map[string]string{"message": "id must be an integer"})
		return
	}
	task, err := db.Get(Task{}, id)
	if err != nil {
		r.JSON(500, map[string]string{"message": "error while retrieving task"})
		return
	}
	if task == nil {
		r.JSON(404, map[string]string{"message": "task not found"})
		return
	}
	r.JSON(200, task)
}
开发者ID:jmptrader,项目名称:martini-gorp-bootstrap,代码行数:17,代码来源:handlers.go

示例9: ConnectToGame

func (gs *GameServiceImpl) ConnectToGame(db *gorp.DbMap, gameId string, playerObj interface{}) (*Game, *Player, error) {
	obj, err := db.Get(Game{}, gameId)
	if err != nil {
		return nil, nil, err
	}
	if obj == nil {
		return nil, nil, errors.New("Player not saved to session")
	}
	game := obj.(*Game)

	var player *Player
	if playerObj == nil { // no, it's a new player
		player = &Player{
			Game: game.Id,
		}

		// save to db so we can find them if they disconnect
		err = db.Insert(player)
		if err != nil {
			return nil, nil, err
		}
	} else { // player is rejoining
		playerObj, err := db.Get(Player{}, playerObj)
		if err != nil {
			return nil, nil, err
		}
		player = playerObj.(*Player)
		// TODO: this would screw with any games they are currently already in?
		if player.Game != game.Id {
			player.Game = game.Id
			count, err := db.Update(player)
			if count == 0 {
				return nil, nil, errors.New("Player update effected 0 rows")
			}
			if err != nil {
				return nil, nil, err
			}
			log.Printf("Joining player id is: %#v", player.Id)
		} else {
			log.Printf("Returning player id is: %#v", player.Id)
		}
	}

	return game, player, nil
}
开发者ID:jakecoffman,项目名称:game-server,代码行数:45,代码来源:services.go

示例10: GetJail

func GetJail(db *gorp.DbMap, field map[string]interface{}) *Jail {
	uuid := LookupUUID(db, field)
	if len(uuid) == 0 {
		return nil
	}

	obj, err := db.Get(Jail{}, uuid)
	if err != nil {
		panic(err)
		return nil
	}

	if obj == nil {
		/* Jail not found */
		return nil
	}

	return obj.(*Jail)
}
开发者ID:virtbsd,项目名称:jail,代码行数:19,代码来源:jail.go

示例11: main

func main() {
	var (
		dbMap *gorp.DbMap
		user  *User
		iUser interface{}
	)

	dbMap = SetupDb()

	//START CODE OMIT
	dbMap.Insert(&User{Id: 1, FirstName: "John", LastName: "Doe"})
	PrintTable(dbMap)

	iUser, _ = dbMap.Get(User{}, 1)
	user = iUser.(*User)

	user.FirstName = "James"
	dbMap.Update(user)
	PrintTable(dbMap)

	dbMap.Delete(user)
	PrintTable(dbMap)
	//END CODE OMIT
}
开发者ID:GoSteelProgrammers,项目名称:talk-review-orms,代码行数:24,代码来源:crud.go


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