當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。