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


Golang hstore.Hstore類代碼示例

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


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

示例1: Value

func (h Hstore) Value() (driver.Value, error) {
	hstore := hstore.Hstore{Map: map[string]sql.NullString{}}
	if len(h) == 0 {
		return nil, nil
	}

	for key, value := range h {
		hstore.Map[key] = sql.NullString{String: *value, Valid: true}
	}
	return hstore.Value()
}
開發者ID:jcrussell,項目名稱:crawlol,代碼行數:11,代碼來源:postgres.go

示例2: saveBallotToDB

func saveBallotToDB(ballot *Ballot) error {
	// Frist transform the tagset into an hstore
	var tags hstore.Hstore
	tags.Map = make(map[string]sql.NullString, len(ballot.TagSet))
	for key, value := range ballot.TagSet.Map() {
		tags.Map[key] = sql.NullString{value, true}
	}

	_, err := db.Exec("INSERT INTO ballots_"+ballot.ElectionID+" (ballot_id, ballot, tags) VALUES ($1, $2, $3)", ballot.BallotID, ballot.String(), tags)
	return err
}
開發者ID:laprice,項目名稱:cryptoballot,代碼行數:11,代碼來源:vote-handler.go

示例3: Value

func (h Hstore) Value() (driver.Value, error) {
	hstore := hstore.Hstore{Map: map[string]sql.NullString{}}
	if len(h) == 0 {
		return nil, nil
	}

	for key, value := range h {
		var s sql.NullString
		if value != nil {
			s.String = *value
			s.Valid = true
		}
		hstore.Map[key] = s
	}
	return hstore.Value()
}
開發者ID:lue828,項目名稱:osinstall-server,代碼行數:16,代碼來源:postgres.go

示例4: Value

// Value implements the driver.Value interface.
func (cm CommandMap) Value() (driver.Value, error) {
	m := make(map[string]sql.NullString)

	for k, v := range cm {
		m[string(k)] = sql.NullString{
			Valid:  true,
			String: string(v),
		}
	}

	h := hstore.Hstore{
		Map: m,
	}

	return h.Value()
}
開發者ID:aaithal,項目名稱:empire,代碼行數:17,代碼來源:processes.go

示例5: Scan

// Scan implements the sql.Scanner interface.
func (cm *CommandMap) Scan(src interface{}) error {
	h := hstore.Hstore{}
	if err := h.Scan(src); err != nil {
		return err
	}

	m := make(CommandMap)

	for k, v := range h.Map {
		m[ProcessType(k)] = Command(v.String)
	}

	*cm = m

	return nil
}
開發者ID:aaithal,項目名稱:empire,代碼行數:17,代碼來源:processes.go

示例6: Value

// Value implements the driver.Value interface.
func (v Vars) Value() (driver.Value, error) {
	m := make(map[string]sql.NullString)

	for k, v := range v {
		m[string(k)] = sql.NullString{
			Valid:  true,
			String: *v,
		}
	}

	h := hstore.Hstore{
		Map: m,
	}

	return h.Value()
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:17,代碼來源:configs.go

示例7: Scan

// Scan implements the sql.Scanner interface.
func (v *Vars) Scan(src interface{}) error {
	h := hstore.Hstore{}
	if err := h.Scan(src); err != nil {
		return err
	}

	vars := make(Vars)

	for k, v := range h.Map {
		// Go reuses the same address space for v, so &v.String would always
		// return the same address
		tmp := v.String
		vars[Variable(k)] = &tmp
	}

	*v = vars

	return nil
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:20,代碼來源:configs.go

示例8: Scan

func (h *Hstore) Scan(value interface{}) error {
	hstore := hstore.Hstore{}

	if err := hstore.Scan(value); err != nil {
		return err
	}

	if len(hstore.Map) == 0 {
		return nil
	}

	*h = Hstore{}
	for k := range hstore.Map {
		if hstore.Map[k].Valid {
			s := hstore.Map[k].String
			(*h)[k] = &s
		} else {
			(*h)[k] = nil
		}
	}

	return nil
}
開發者ID:lue828,項目名稱:osinstall-server,代碼行數:23,代碼來源:postgres.go

示例9: saveElectionToDB

func saveElectionToDB(election *Election) error {
	// Frist transform the tagset into an hstore
	var tags hstore.Hstore
	tags.Map = make(map[string]sql.NullString, len(election.TagSet))
	for key, value := range election.TagSet.Map() {
		tags.Map[key] = sql.NullString{String: value, Valid: true}
	}

	_, err := db.Exec("INSERT INTO elections (election_id, election, startdate, enddate, tags) VALUES ($1, $2, $3, $4, $5)", election.ElectionID, election.String(), election.Start, election.End, tags)
	if err != nil {
		return err
	}

	// Create the sigreqa table for storing signature requests
	_, err = db.Exec(strings.Replace(sigreqsQuery, "<election-id>", election.ElectionID, -1))
	if err != nil {
		return err
	}

	//@@TODO - tell ballotbox database about election

	return nil
}
開發者ID:laprice,項目名稱:cryptoballot,代碼行數:23,代碼來源:election-handler.go


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