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


Golang NullTime.Valid方法代碼示例

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


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

示例1: EntitySetNull

func EntitySetNull(
	entity *df.Entity, propertyName string, colInfo *df.ColumnInfo, update bool) {
	switch colInfo.GoType {
	case "string":
		df.SetEntityValue(entity, propertyName, "")
	case "sql.NullString":
		df.SetEntityValue(entity, propertyName, new(sql.NullString))
	case "pq.NullTime":
		nt := new(pq.NullTime)
		nt.Valid = false
		df.SetEntityValue(entity, propertyName, nt)
	case "df.NullDate":
		df.SetEntityValue(entity, propertyName, new(df.NullDate))
	case "df.NullTimestamp":
		df.SetEntityValue(entity, propertyName, new(df.NullTimestamp))
	case "df.NullNumeric":
		df.SetEntityValue(entity, propertyName, new(df.NullNumeric))
	case "df.MysqlNullDate":
		df.SetEntityValue(entity, propertyName, new(df.MysqlNullDate))
	case "df.MysqlNullTime":
		df.SetEntityValue(entity, propertyName, new(df.MysqlNullTime))
	case "df.MysqlNullTimestamp":
		df.SetEntityValue(entity, propertyName, new(df.MysqlNullTimestamp))
	case "sql.NullInt64":
		df.SetEntityValue(entity, propertyName, new(sql.NullInt64))
	case "sql.NullFloat64":
		df.SetEntityValue(entity, propertyName, new(sql.NullFloat64))
	case "sql.NullBool":
		df.SetEntityValue(entity, propertyName, new(sql.NullBool))
	default:
		if update {
			panic("必須項目未入力です。 項目名:" + propertyName)
		}
	}
}
開發者ID:mikeshimura,項目名稱:go-dbflute-example,代碼行數:35,代碼來源:util.go

示例2: CreateNullTime

func CreateNullTime(v time.Time) pq.NullTime {
	var nt pq.NullTime
	nt.Valid = true
	nt.Time = v
	return nt
}
開發者ID:mikeshimura,項目名稱:go-dbflute-example,代碼行數:6,代碼來源:util.go

示例3: convertArt

// convertArt converts a slurped article into jl form
func convertArt(src *slurp.Article) (*jl.Article, []*jl.UnresolvedJourno) {
	now := time.Now()

	bestURL := src.CanonicalURL
	if bestURL == "" {
		bestURL = src.URLs[0]
	}

	pub := jl.NewPublication(src.Publication.Domain, src.Publication.Name)

	var pubDate pq.NullTime
	t, err := time.Parse(time.RFC3339, src.Published)
	if err == nil {
		pubDate.Time = t
		pubDate.Valid = true
	} // else pubDate is NULL

	wordCnt := sql.NullInt64{0, false}
	rawTxt := ""
	if src.Content != "" {
		// parse and render to raw text
		doc, err := html.Parse(strings.NewReader(src.Content))
		if err == nil {
			rawTxt = htmlutil.RenderNode(doc)
		}
	}

	tags := []jl.Tag{}
	if rawTxt != "" {
		// count words
		cnt := len(wordPat.FindAllString(rawTxt, -1))
		if cnt > 0 {
			wordCnt = sql.NullInt64{int64(cnt), true}
		}

		tags = jl.ExtractTagsFromText(rawTxt)
	}

	art := &jl.Article{
		ID:          0, // note: we generate our own IDs at the JL end
		Title:       src.Headline,
		Byline:      "",
		Description: "",
		Content:     src.Content,
		PubDate:     pubDate,
		FirstSeen:   now,
		LastSeen:    now,
		Permalink:   bestURL,
		SrcURL:      bestURL,
		URLs:        make([]string, len(src.URLs)),
		Publication: pub,
		LastScraped: pq.NullTime{now, true},

		WordCount: wordCnt,
		Status:    'a',
		Tags:      tags,
	}
	copy(art.URLs, src.URLs)

	// authors
	authors := []*jl.UnresolvedJourno{}
	for _, a := range src.Authors {
		u := &jl.UnresolvedJourno{
			Name: a.Name,
			// TODO: Email, rel-author, twitter, etc..
		}
		authors = append(authors, u)
	}
	return art, authors
}
開發者ID:bcampbell,項目名稱:journalisted,代碼行數:71,代碼來源:main.go


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