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


Golang pq.NullTime类代码示例

本文整理汇总了Golang中github.com/lib/pq.NullTime的典型用法代码示例。如果您正苦于以下问题:Golang NullTime类的具体用法?Golang NullTime怎么用?Golang NullTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NullTime类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestTimeOrNull

func TestTimeOrNull(t *testing.T) {
	var (
		nullTime pq.NullTime
		value    driver.Value
		err      error
	)

	// When the time is nil
	nullTime = TimeOrNull(nil)

	// nullTime.Valid should be false
	assert.False(t, nullTime.Valid)

	// nullInt.Value() should return nil
	value, err = nullTime.Value()
	assert.Nil(t, err)
	assert.Nil(t, value)

	// When the time is time.Time instance
	now := time.Now()
	nullTime = TimeOrNull(&now)

	// nullTime.Valid should be true
	assert.True(t, nullTime.Valid)

	// nullTime.Value() should return the time.Time
	value, err = nullTime.Value()
	assert.Nil(t, err)
	assert.Equal(t, now, value)
}
开发者ID:chenhougen,项目名称:go-oauth2-server,代码行数:30,代码来源:util_test.go

示例3: setTimer

func setTimer(rows *sql.Rows) (*Timer, error) {
	var finishedAt pq.NullTime
	var createdAt pq.NullTime

	timer := Timer{}

	err := rows.Scan(&timer.ID, &timer.User, &timer.Name, &createdAt, &finishedAt)
	if err != nil {
		return nil, err
	}

	val, err := createdAt.Value()
	if err != nil {
		return nil, err
	}

	if val != nil {
		timer.CreatedAt = &createdAt.Time
	}

	val, err = finishedAt.Value()
	if err != nil {
		return nil, err
	}

	if val != nil {
		timer.FinishedAt = &finishedAt.Time
	}

	return &timer, nil
}
开发者ID:gistia,项目名称:slackbot,代码行数:31,代码来源:timers.go

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

示例5: TimeOrNull

// TimeOrNull returns properly confiigured pq.TimeNull
func TimeOrNull(t interface{}) pq.NullTime {
	nullTime := new(pq.NullTime)
	nullTime.Scan(t)
	return *nullTime
}
开发者ID:kunalshah,项目名称:go-oauth2-server,代码行数:6,代码来源:util.go

示例6: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。