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


Golang DbMap.Insert方法代码示例

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


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

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

示例2: AddPage

func AddPage(Db *gorp.DbMap, fullurl string) (SitePage, error) {
	fullurl = n(fullurl)
	u, _ := url.Parse(fullurl)
	res := SitePage{}
	if IsExistPage(Db, fullurl) {
		return res, errors.New("exist")
	}

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

	site, err := GetSite(Db, fullurl)
	if err != nil {
		return res, errors.New("site not exist")
	}

	res.SiteId = site.Id
	res.Url = u.RequestURI()

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

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

示例3: SetForItem

func SetForItem(db *gorp.DbMap, tagId, itemId int64, itemType string) error {
	t := Tags{}
	t.Id = tagId
	t.ItemId = itemId
	t.ItemType = itemType
	return db.Insert(&t)
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:7,代码来源:tags.go

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

示例5: PostUser

func PostUser(r render.Render, dbmap *gorp.DbMap, res http.ResponseWriter, u User, e binding.Errors) {
	if e != nil {
		r.JSON(http.StatusBadRequest, map[string]string{"message": e[0].Message})
		return
	}
	//check user exists yet or not?
	var count int64
	count, err := dbmap.SelectInt("SELECT count(*) FROM CUSTOMER WHERE CUS_TEL=?", u.PhoneNumber)
	if err != nil {
		glog.V(1).Infof("[DEBUG:] Search customer by tel:%v fail:%v", u.PhoneNumber, err)
		r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
		return
	}

	if count > 0 {
		glog.V(1).Infof("Customer with tel:%v exists yet", u.PhoneNumber)
		r.JSON(http.StatusConflict, map[string]string{"message": "User with same Tel exists"})
		return
	}

	//insert new user info to db;
	err = dbmap.Insert(&u)
	if err != nil {
		glog.V(1).Infof("[DEBUG:] Insert customer %v fail:%v", u, 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,代码行数:29,代码来源:users.go

示例6: createTag

func createTag(db *gorp.DbMap, t Tag) (Tag, error) {
	var err error
	if !tagExist(db, t.Title) {
		err = db.Insert(&t)
	}
	return t, err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:7,代码来源:tags.go

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

示例8: ProductsCreate

func ProductsCreate(product models.Product, db *gorp.DbMap, render render.Render) {
	err := db.Insert(&product)
	if err == nil {
		render.JSON(201, &product)
	} else {
		render.JSON(422, map[string]string{"error": err.Error()})
	}
}
开发者ID:joiggama,项目名称:martini-example,代码行数:8,代码来源:products.go

示例9: MustCreateAccount

func MustCreateAccount(dbmap *gorp.DbMap, email string) *rr.Account {
	account := rr.NewAccount(email)
	err := dbmap.Insert(account)
	if err != nil {
		panic(err.Error())
	}
	return account
}
开发者ID:DaleWebb,项目名称:readraptor,代码行数:8,代码来源:readraptor_test.go

示例10: Create

func (r Rate) Create(Db *gorp.DbMap, itemType int64, itemId int64) Rate {
	rn := r.GetRate(Db, itemType, itemId)
	if rn.Id == 0 {
		r.ItemId = itemId
		r.ItemType = itemType
		Db.Insert(&r)
	}
	return r
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:9,代码来源:rate.go

示例11: AddToIndex

func AddToIndex(db *gorp.DbMap, keys []string, itemtype string, itemid int64) error {
	i := SearchIndex{
		Type:   itemtype,
		ItemId: itemid,
		Weight: 0,
		Keys:   strings.Join(keys, " "),
	}
	return db.Insert(&i)
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:9,代码来源:db.go

示例12: AddTask

func AddTask(r render.Render, taskPayload Task, db *gorp.DbMap) {
	err := db.Insert(&taskPayload)
	if err != nil {
		log.Printf("Error inserting: %v", err)
		r.JSON(400, map[string]string{"message": "failed inserting task"})
		return
	}
	r.JSON(201, taskPayload)
}
开发者ID:jmptrader,项目名称:martini-gorp-bootstrap,代码行数:9,代码来源:handlers.go

示例13: PlayerInit

func PlayerInit(playerId int, gameId string, gs GameService, ws *websocket.Conn, db *gorp.DbMap) error {
	log.Printf("Player is connected: %#v", playerId)

	game, _, err := gs.GetGame(db, gameId, playerId)
	if err != nil {
		log.Printf("Couldn't get player and/or game")
		return err
	}

	if game.State == "start" {
		log.Printf("Player %#v rejoining game in play", playerId)
		board, err := getBoard(gameId, db)
		if err != nil {
			log.Printf("Can't get TTT board: %#v", err)
			return err
		}

		log.Printf("Got board, getting nicer one: %#v", board)
		niceBoard, err := board.getBoard()
		if err != nil {
			log.Printf("Unable to get nice board: %#v", err)
			return err
		}
		log.Printf("Got board for player %#v: %#v", playerId, board)

		// There may not be a board yet so just try and send it
		ws.WriteJSON(Message{
			"type":  "update",
			"state": game.State,
			"board": niceBoard,
		})
	} else {
		ws.WriteJSON(Message{
			"type":  "update",
			"state": game.State,
			"board": nil,
		})
	}

	// check to make sure this player has a turn row
	turn := TicTacToe_Turn{}
	err = db.SelectOne(&turn, "select * from tictactoe_turn where game=? and player=?", gameId, playerId)
	if err != nil {
		turn.Game = gameId
		turn.Player = playerId
		turn.Move = -1
		err = db.Insert(&turn)
		if err != nil {
			log.Printf("Unable to insert initial turn row: %#v", err)
			return err
		}
	}

	gs.SendHost(gameId, Message{"type": "join"})
	return nil
}
开发者ID:jakecoffman,项目名称:game-server,代码行数:56,代码来源:tictactoe.go

示例14: CreateAddr

func CreateAddr(db *gorp.DbMap, addr string) Address {
	var a Address
	var err error
	a, err = GetAddr(db, addr)
	if err != nil && err.Error() == ErrorNotFound {
		a.RawText = addr
		db.Insert(&a)
	}
	return a
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:10,代码来源:address.go

示例15: ProductsBulkCreate

func ProductsBulkCreate(products models.Products, db *gorp.DbMap, render render.Render) {
	for _, product := range products.Collection {
		err := db.Insert(&product)
		if err != nil {
			panic(err)
		}
	}

	render.JSON(201, products)
}
开发者ID:joiggama,项目名称:martini-example,代码行数:10,代码来源:products.go


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