本文整理汇总了Golang中github.com/lib/pq/hstore.Hstore.Map方法的典型用法代码示例。如果您正苦于以下问题:Golang Hstore.Map方法的具体用法?Golang Hstore.Map怎么用?Golang Hstore.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lib/pq/hstore.Hstore
的用法示例。
在下文中一共展示了Hstore.Map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}