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


Golang DbMap.Update方法代码示例

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


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

示例1: SignUp

func (u *User) SignUp(db *gorp.DbMap, s SmsSender, firstname, lastname, phone,
	password string) error {
	u.FirstName = firstname
	u.LastName = lastname
	u.Phone = phone
	u.HashedPassword, _ = bcrypt.GenerateFromPassword(
		[]byte(password), bcrypt.DefaultCost)

	_, err := db.Update(u)
	if err != nil {
		return err
	}

	conf, err := generateConfirmation(db, u.Id)
	if err != nil {
		return err
	}

	message := fmt.Sprintf("You code %d. Session %d.", conf.Code, conf.Id)

	err = s.Send(phone, message)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:27,代码来源:db.go

示例2: Edit

func Edit(db *gorp.DbMap, w WikiPage) (WikiPage, bool) {
	if w.Id == 0 {
		db.Insert(&w)
	} else {
		wOld, ok := GetBySlug(db, w.Title)
		if !ok {
			return WikiPage{}, false
		}
		textOld := string(wOld.Body)
		textNew := string(w.Body)

		d := diffmatchpatch.New()
		b := d.DiffMain(textNew, textOld, false)

		dl := d.DiffToDelta(b)

		delta := WikiDelta{
			ItemId:    w.Id,
			PrevDelta: w.PrevDelta,
			Delta:     []byte(dl),
		}

		db.Insert(&delta)

		w.PrevDelta = delta.Id

		db.Update(&w)
	}
	return w, true
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:30,代码来源:wiki.go

示例3: insertOrUpdateContact

func insertOrUpdateContact(dbmap *gorp.DbMap, user, contactid, contactname, group string) error {
	var contacts []Contact
	_, err := dbmap.Select(&contacts, "SELECT * FROM contacts WHERE User=? AND ContactId=?", user, contactid)
	if err != nil {
		return err
	}

	if len(contacts) == 0 {
		contact := Contact{
			User:        user,
			ContactId:   contactid,
			ContactName: contactname,
			Group:       group,
		}
		err = dbmap.Insert(&contact)
		if err != nil {
			return err
		}
	} else if len(contacts) == 1 {
		contact := contacts[0]
		contact.ContactName = contactname
		contact.Group = group
		_, err = dbmap.Update(&contact)
		if err != nil {
			return err
		}
	} else {
		return errors.New("You have more than one contacts")
	}
	return nil
}
开发者ID:Narsil,项目名称:smsportal-server,代码行数:31,代码来源:smsserver.go

示例4: NewPassword

func (u *User) NewPassword(db *gorp.DbMap, password string) error {
	u.HashedPassword, _ = bcrypt.GenerateFromPassword(
		[]byte(password), bcrypt.DefaultCost)
	u.Updated = time.Now().UnixNano()
	_, err := db.Update(u)
	return err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:7,代码来源:db.go

示例5: hostState

func hostState(msg Message, gameId string, playerId int, gs GameService, ws *websocket.Conn, db *gorp.DbMap, log *log.Logger) error {
	log.Printf("Got state change request from host: %v", msg["state"])

	game, _, err := gs.GetGame(db, gameId, playerId)
	if err != nil {
		log.Printf("%#v", err)
		return err
	}

	// TODO: check to make sure this is a valid state
	game.State = msg["state"].(string)
	var board *TicTacToe_Board
	if game.State == "start" {
		board = &TicTacToe_Board{Game: gameId}
		log.Printf("Setting up starting objects")
		// we are starting a game, so insert a new board
		err = board.setBoard([]int{0, 0, 0, 0, 0, 0, 0, 0, 0})
		if err != nil {
			log.Printf("Unable to set game board: %#v", err)
			return err
		}
		log.Printf("Inserting board: %#v", board)
		err = db.Insert(board)
		if err != nil {
			log.Printf("Couldn't insert board: %#v", err)
			return err
		}
	} else {
		board, err = getBoard(gameId, db)
		if err != nil {
			log.Printf("Unable to get board: %#v", err)
			return err
		}
	}
	log.Printf("Updating game state to %#v", game.State)
	count, err := db.Update(game)
	if err != nil || count == 0 {
		log.Printf("Unable to change game state: %v", err)
		return err
	}
	niceBoard, err := board.getBoard()
	if err != nil {
		log.Printf("Error getting board: %#v", board)
		return err
	}
	log.Printf("Sending state %v to all players", msg["state"])
	gs.Broadcast(gameId, Message{
		"type":  "update",
		"board": niceBoard,
		"state": "start",
	})
	log.Printf("Updating UI")
	ws.WriteJSON(Message{
		"type":  "update",
		"board": niceBoard,
		"state": "start",
	})
	return nil
}
开发者ID:jakecoffman,项目名称:game-server,代码行数:59,代码来源:tictactoe.go

示例6: Update

func Update(db *gorp.DbMap, c ChangeLog) error {
	old, err := Get(db, c.Id)
	if err != nil {
		return err
	}
	old.Updated = time.Now().UTC().UnixNano()
	old.Body = c.Body
	old.Title = c.Title
	_, err = db.Update(&old)
	return err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:11,代码来源:changelog.go

示例7: ProductsUpdate

// Currently there's no way to only update specific columns, update maps struct fields to table :(
// https://github.com/coopernurse/gorp/issues/92
func ProductsUpdate(product models.Product, db *gorp.DbMap, params martini.Params, render render.Render) {
	id, _ := strconv.ParseInt(params["id"], 0, 64)
	product.Id = id
	_, err := db.Update(&product)

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

示例8: Update

func Update(db *gorp.DbMap, u User) error {
	t := time.Now().UnixNano()
	ou, err := Get(db, u.Id)
	if err != nil {
		return err
	}
	ou.FirstName = u.FirstName
	ou.LastName = u.LastName
	ou.Patronymic = u.Patronymic
	ou.Updated = t
	_, err = db.Update(&ou)
	return err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:13,代码来源:db.go

示例9: UpdateNew

func UpdateNew(db *gorp.DbMap, n New) error {
	oldnew, err := GetNew(db, n.Id)
	if err != nil {
		return err
	}
	n.Created = oldnew.Created
	n.Version = oldnew.Version
	n.Slug = oldnew.Slug
	t := time.Now().UTC().UnixNano()
	n.Updated = t
	_, err = db.Update(&n)
	return err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:13,代码来源:db.go

示例10: Persist

func (network *Network) Persist(db *gorp.DbMap) error {
	if len(network.UUID) == 0 {
		obj := GetNetwork(map[string]interface{}{"dbmap": db}, map[string]interface{}{"name": network.Name})
		if obj == nil {
			uuid, _ := uuid.NewV4()
			network.UUID = uuid.String()
			db.Insert(network)
		} else {
			network.UUID = obj.UUID
			db.Update(network)
		}
	} else {
		db.Update(network)
	}

	for _, address := range network.Addresses {
		if len(address.DeviceUUID) == 0 {
			address.DeviceUUID = network.UUID
		}

		if address.DeviceAddressID == 0 {
			db.Insert(address)
		} else {
			db.Update(address)
		}
	}

	for _, option := range network.Options {
		option.DeviceUUID = network.UUID

		if option.DeviceOptionID == 0 {
			db.Insert(option)
		} else {
			db.Update(option)
		}
	}

	for _, physical := range network.Physicals {
		if len(physical.NetworkUUID) == 0 {
			physical.NetworkUUID = network.UUID
		}

		if physical.NetworkPhysicalID == 0 {
			db.Insert(physical)
		} else {
			db.Update(physical)
		}
	}

	return nil
}
开发者ID:virtbsd,项目名称:network,代码行数:51,代码来源:network.go

示例11: Persist

func (jail *Jail) Persist(db *gorp.DbMap) error {
	insert := false

	if len(jail.UUID) == 0 {
		insert = true
		count := 0

		db.Select(&count, "select count(UUID) from Jail where Name = ?", jail.Name)
		if count > 0 {
			return fmt.Errorf("Jail with name %s already exists", jail.Name)
		}
	}

	if err := jail.Validate(); err != nil {
		return err
	}

	if insert {
		db.Insert(jail)
	} else {
		db.Update(jail)
	}

	for _, device := range jail.NetworkDevices {
		device.VmUUID = jail.UUID
		if err := device.Persist(db, jail); err != nil {
			return err
		}
	}

	for _, mount := range jail.Mounts {
		if mount.MountPointID == 0 {
			mount.JailUUID = jail.UUID
			db.Insert(mount)
		} else {
			db.Update(mount)
		}
	}

	for _, option := range jail.Options {
		if option.OptionID == 0 {
			option.JailUUID = jail.UUID
			db.Insert(option)
		} else {
			db.Update(option)
		}
	}

	for _, route := range jail.Routes {
		if route.RouteID == 0 {
			route.VmUUID = jail.UUID
			db.Insert(route)
		} else {
			db.Update(route)
		}
	}

	return nil
}
开发者ID:virtbsd,项目名称:jail,代码行数:59,代码来源:jail.go

示例12: VisitPage

func VisitPage(Db *gorp.DbMap, fullurl string, body []byte, code int) error {
	res := SitePage{}
	var err error

	fullurl = n(fullurl)
	u, _ := url.Parse(fullurl)

	if !IsExistSite(Db, fullurl) {
		_, err = AddSite(Db, fullurl)
		if err != nil {
			return err
		}
	}

	if !IsExistPage(Db, fullurl) {
		res.Url = u.RequestURI()
		res.Error = int64(code)
		res.Body = gz.Gz(string(body))
		res.Visited = time.Now().UnixNano()

		site, err := GetSite(Db, fullurl)
		if err != nil {
			return err
		}
		res.SiteId = site.Id

		err = Db.Insert(&res)
		if err != nil {
			return err
		}

		return nil

	} else {
		res, err = GetPage(Db, fullurl)
		if err != nil {
			return err
		}
	}

	res.Error = int64(code)
	res.Body = gz.Gz(string(body))
	res.Visited = time.Now().UnixNano()

	_, err = Db.Update(&res)

	return err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:48,代码来源:db.go

示例13: 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

示例14: Confirm

func (u *User) Confirm(db *gorp.DbMap, code int64, userid int64) error {
	var uc = UserConfirmation{}
	err := db.SelectOne(&uc, "select * from UserConfirmation where UserId = ? and Code = ?"+
		" and Tried = 0 and Created > ?", userid, code, time.Now().Truncate(5*
		time.Minute).UnixNano())
	if err != nil {
		return err
	}
	if uc.Id == 0 {
		return errors.New("Confirmation not found")
	}
	u.Registered = true
	_, err = db.Update(u)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:18,代码来源:db.go

示例15: PutGoods

func PutGoods(r render.Render, dbmap *gorp.DbMap, params martini.Params, res http.ResponseWriter, g GoodInfo, e binding.Errors) {
	id := params["id"]
	//get userinfo
	_, err := goods.GetGoodsById(id, dbmap)
	if err != nil {
		r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
	}

	//insert new user info to db;
	_, err = dbmap.Update(&g)
	if err != nil {
		glog.V(1).Infof("[DEBUG:] Update Goods %v fail:%v", g, err)
		r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
		return
	}

	r.JSON(200, map[string]string{"message": "SUCCESS"})
}
开发者ID:renhuiyang,项目名称:go-shoppingweb-practise,代码行数:18,代码来源:goods.go


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