當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Item.ID方法代碼示例

本文整理匯總了Golang中rter/data.Item.ID方法的典型用法代碼示例。如果您正苦於以下問題:Golang Item.ID方法的具體用法?Golang Item.ID怎麽用?Golang Item.ID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rter/data.Item的用法示例。


在下文中一共展示了Item.ID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSelectItem

func TestSelectItem(t *testing.T) {
	selectedItem := new(data.Item)
	selectedItem.ID = item.ID
	err := Select(selectedItem)

	if err != nil {
		t.Error(err)
	}

	t.Log(item.StartTime.UTC())
	t.Log(selectedItem.StartTime.UTC())

	t.Log(item.StopTime.UTC())
	t.Log(selectedItem.StopTime.UTC())

	selectedItem.StartTime = item.StartTime // hack
	selectedItem.StopTime = item.StopTime   // hack

	structJSONCompare(t, item, selectedItem)
}
開發者ID:falahhaprak,項目名稱:rter,代碼行數:20,代碼來源:storage_test.go

示例2: Insert

func Insert(val interface{}) error {
	var (
		res sql.Result
		err error
	)

	now := time.Now().UTC()

	switch v := val.(type) {
	case *data.Item:
		res, err = Exec(
			"INSERT INTO Items (Type, Author, ThumbnailURI, ContentURI, UploadURI, ContentToken, HasHeading, Heading, HasGeo, Lat, Lng, Radius, Live, StartTime, StopTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			v.Type,
			v.Author,
			v.ThumbnailURI,
			v.ContentURI,
			v.UploadURI,
			v.ContentToken,
			v.HasHeading,
			v.Heading,
			v.HasGeo,
			v.Lat,
			v.Lng,
			v.Radius,
			v.Live,
			v.StartTime.UTC(),
			v.StopTime.UTC(),
		)
	case *data.ItemComment:
		res, err = Exec(
			"INSERT INTO ItemComments (ItemID, Author, Body, UpdateTime) VALUES (?, ?, ?, ?)",
			v.ItemID,
			v.Author,
			v.Body,
			now,
		)
	case *data.Geolocation:
		res, err = Exec(
			"INSERT INTO Geolocations (ItemID, Lat, Lng, Heading, Radius, Timestamp) VALUES (?, ?, ?, ?, ?, ?)",
			v.ItemID,
			v.Lat,
			v.Lng,
			v.Heading,
			v.Radius,
			now,
		)
	case *data.Term:
		// There is basically no danger with INSERT IGNORE there is nothing we would want to change if there is
		// accidental remake of a term
		res, err = Exec(
			"INSERT IGNORE INTO Terms (Term, Automated, Author, UpdateTime) VALUES (?, ?, ?, ?)",
			v.Term,
			v.Automated,
			v.Author,
			now,
		)
	case *data.TermRelationship:
		// Nothing can go wrong with INSERT IGNORE since the key is whole entry
		res, err = Exec(
			"INSERT IGNORE INTO TermRelationships (Term, ItemID) VALUES (?, ?)",
			v.Term,
			v.ItemID,
		)
	case *data.TermRanking:
		// There is basically no danger with INSERT IGNORE there is nothing we would want to change if there is
		// accidental remake of a term
		res, err = Exec(
			"INSERT IGNORE INTO TermRankings (Term, Ranking, UpdateTime) VALUES (?, ?, ?)",
			v.Term,
			v.Ranking,
			now,
		)
	case *data.Role:
		res, err = Exec(
			"INSERT INTO Roles (Title, Permissions) VALUES (?, ?)",
			v.Title,
			v.Permissions,
		)
	case *data.User:
		res, err = Exec(
			"INSERT INTO Users (Username, Password, Salt, Role, TrustLevel, CreateTime) VALUES (?, ?, ?, ?, ?, ?)",
			v.Username,
			v.Password,
			v.Salt,
			v.Role,
			v.TrustLevel,
			now,
		)
	case *data.UserDirection:
		res, err = Exec(
			"INSERT INTO UserDirections (Username, LockUsername, Command, Heading, Lat, Lng, UpdateTime) VALUES (?, ?, ?, ?, ?, ?, ?)",
			v.Username,
			v.LockUsername,
			v.Command,
			v.Heading,
			v.Lat,
			v.Lng,
			now,
		)
	default:
//.........這裏部分代碼省略.........
開發者ID:cyc115,項目名稱:rter-new,代碼行數:101,代碼來源:driver.go


注:本文中的rter/data.Item.ID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。