本文整理汇总了Golang中database/sql.Row类的典型用法代码示例。如果您正苦于以下问题:Golang Row类的具体用法?Golang Row怎么用?Golang Row使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Row类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ScanIssue
func ScanIssue(row *sql.Row) (*Issue, error) {
var v0 int64
var v1 int
var v2 string
var v3 string
var v4 string
var v5 string
var v6 []byte
err := row.Scan(
&v0,
&v1,
&v2,
&v3,
&v4,
&v5,
&v6,
)
if err != nil {
return nil, err
}
v := &Issue{}
v.ID = v0
v.Number = v1
v.Title = v2
v.Body = v3
v.Assignee = v4
v.State = v5
json.Unmarshal(v6, &v.Labels)
return v, nil
}
示例2: extractPost
func extractPost(row *sql.Row) (*structure.Post, error) {
post := structure.Post{}
var userId int64
var status string
err := row.Scan(&post.Id, &post.Uuid, &post.Title, &post.Slug, &post.Markdown, &post.Html, &post.IsFeatured, &post.IsPage, &status, &post.Image, &userId, &post.Date)
if err != nil {
return nil, err
}
// If there was no publication date attached to the post, make its creation date the date of the post
if post.Date == nil {
post.Date, err = retrievePostCreationDateById(post.Id)
if err != nil {
return nil, err
}
}
// Evaluate status
if status == "published" {
post.IsPublished = true
} else {
post.IsPublished = false
}
// Retrieve user
post.Author, err = RetrieveUser(userId)
if err != nil {
return nil, err
}
// Retrieve tags
post.Tags, err = RetrieveTags(post.Id)
if err != nil {
return nil, err
}
return &post, nil
}
示例3: populateVideo
// Populates a video + type
func populateVideo(row *sql.Row, ch chan Video) {
var v Video
var tName, tIcon *string
err := row.Scan(
&v.ID,
&v.VideoType.ID,
&v.Title,
&v.Description,
&v.DateAdded,
&v.DateModified,
&v.IsPrimary,
&v.Thumbnail,
&tName,
&tIcon,
)
if err != nil {
ch <- v
return
}
if tName != nil {
v.VideoType.Name = *tName
}
if tIcon != nil {
v.VideoType.Icon = *tIcon
}
ch <- v
return
}
示例4: rowToCompte
func rowToCompte(trollId int, row *sql.Row) (*Compte, error) {
c := new(Compte)
c.trollId = trollId
c.Troll = new(TrollData)
err := row.Scan(
&c.statut,
&c.mdpRestreint,
&c.Troll.PV_max,
&c.Troll.PV_actuels,
&c.Troll.X,
&c.Troll.Y,
&c.Troll.Z,
&c.Troll.Fatigue,
&c.Troll.PA,
&c.Troll.Vue,
&c.Troll.ProchainTour,
&c.Troll.DureeTour,
&c.Troll.MiseAJour)
c.Troll.ProchainTour *= 1000
c.Troll.MiseAJour *= 1000
if err != nil {
return nil, err
}
return c, err
}
示例5: QuerySpaceConsumptionFor
// Query the currently used space for the given user
func (tx *Transaction) QuerySpaceConsumptionFor(user string) (result uint64, err error) {
err = tx.do(func(tx *sql.Tx) (err error) {
var row *sql.Row
row = tx.QueryRow(`
SELECT
SUM("u"."size") AS "size"
FROM (
SELECT --DISTINCT
"u"."user" AS "user",
"u"."id" AS "id",
"u"."size" AS "size"
FROM "uploads" AS "u"
WHERE "u"."expiration" >= NOW()
AND "u"."user" = $1
) AS "u"
GROUP BY "u"."user"`,
user)
// Get result - use zero if query returned no result for the given username
err = row.Scan(&result)
if err == sql.ErrNoRows {
result = 0
err = nil
}
return
})
return
}
示例6: populateApplicationGuide
func populateApplicationGuide(row *sql.Row, ch chan ApplicationGuide) {
var ag ApplicationGuide
var catID *int
var icon []byte
var catName *string
err := row.Scan(
&ag.ID,
&ag.Url,
&ag.Website.ID,
&ag.FileType,
&catID,
&icon,
&catName,
)
if err != nil {
ch <- ag
}
if catID != nil {
ag.Category.CategoryID = *catID
}
if catName != nil {
ag.Category.Title = *catName
}
if icon != nil {
ag.Icon = string(icon[:])
}
ch <- ag
return
}
示例7: fetchLocationBySha
// fetchLocationBySha look up the Tx sha information by name.
// Must be called with db lock held.
func (db *SqliteDb) fetchLocationBySha(txsha *btcwire.ShaHash) (blockidx int64, txoff int, txlen int, err error) {
var row *sql.Row
var blockid int64
var ttxoff int
var ttxlen int
rowBytes := txsha.String()
txop := db.txop(txFetchLocationByShaStmt)
row = txop.QueryRow(rowBytes)
err = row.Scan(&blockid, &ttxoff, &ttxlen)
if err == sql.ErrNoRows {
txop = db.txop(txtmpFetchLocationByShaStmt)
row = txop.QueryRow(rowBytes)
err = row.Scan(&blockid, &ttxoff, &ttxlen)
if err == sql.ErrNoRows {
err = btcdb.TxShaMissing
return
}
if err != nil {
log.Warnf("txtmp FetchLocationBySha: fail %v",
err)
return
}
}
if err != nil {
log.Warnf("FetchLocationBySha: fail %v", err)
return
}
blockidx = blockid - 1
txoff = ttxoff
txlen = ttxlen
return
}
示例8: FetchTxUsedBySha
// FetchTxUsedBySha returns the used/spent buffer for a given transaction.
func (db *SqliteDb) FetchTxUsedBySha(txsha *btcwire.ShaHash) (spentbuf []byte, err error) {
var row *sql.Row
db.dbLock.Lock()
defer db.dbLock.Unlock()
rowBytes := txsha.String()
txop := db.txop(txFetchUsedByShaStmt)
row = txop.QueryRow(rowBytes)
var databytes []byte
err = row.Scan(&databytes)
if err == sql.ErrNoRows {
txop := db.txop(txtmpFetchUsedByShaStmt)
row = txop.QueryRow(rowBytes)
err = row.Scan(&databytes)
if err == sql.ErrNoRows {
err = btcdb.TxShaMissing
return
}
if err != nil {
log.Warnf("txtmp FetchLocationBySha: fail %v",
err)
return
}
}
if err != nil {
log.Warnf("FetchUsedBySha: fail %v", err)
return
}
spentbuf = databytes
return
}
示例9: consumeRow
func (t *Topic) consumeRow(row *sql.Row) error {
return row.Scan(
&t.Id,
&t.Name,
&t.CreatedAt,
&t.UpdatedAt,
)
}
示例10: indexExists
func (d mysql) indexExists(mg *Migration, tableName, indexName string) bool {
var row *sql.Row
var name string
row = mg.Db.QueryRow("SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS "+
"WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND INDEX_NAME = ?", mg.DbName, tableName, indexName)
row.Scan(&name)
return name != ""
}
示例11: rowToDBLink
func rowToDBLink(row *sql.Row) *DBLink {
link := DBLink{}
err := row.Scan(&link.Key, &link.Link, &link.Sender_id, &link.Date, &link.Link_type, &link.Sender_name)
if err != nil {
return &DBLink{}
}
return &link
}
示例12: scanSelectSingle
func scanSelectSingle(m *model.Group, row *sql.Row) error {
err := row.Scan(
&m.UID,
&m.Name,
&m.UserUID,
&m.CreatedAt,
)
return err
}
示例13: scanNotification
func (pgSQL *pgSQL) scanNotification(row *sql.Row, hasVulns bool) (database.VulnerabilityNotification, error) {
var notification database.VulnerabilityNotification
var created zero.Time
var notified zero.Time
var deleted zero.Time
var oldVulnerabilityNullableID sql.NullInt64
var newVulnerabilityNullableID sql.NullInt64
// Scan notification.
if hasVulns {
err := row.Scan(
¬ification.ID,
¬ification.Name,
&created,
¬ified,
&deleted,
&oldVulnerabilityNullableID,
&newVulnerabilityNullableID,
)
if err != nil {
return notification, err
}
} else {
err := row.Scan(¬ification.ID, ¬ification.Name, &created, ¬ified, &deleted)
if err != nil {
return notification, err
}
}
notification.Created = created.Time
notification.Notified = notified.Time
notification.Deleted = deleted.Time
if hasVulns {
if oldVulnerabilityNullableID.Valid {
vulnerability, err := pgSQL.findVulnerabilityByIDWithDeleted(int(oldVulnerabilityNullableID.Int64))
if err != nil {
return notification, err
}
notification.OldVulnerability = &vulnerability
}
if newVulnerabilityNullableID.Valid {
vulnerability, err := pgSQL.findVulnerabilityByIDWithDeleted(int(newVulnerabilityNullableID.Int64))
if err != nil {
return notification, err
}
notification.NewVulnerability = &vulnerability
}
}
return notification, nil
}
示例14: MapChar
func MapChar(r *sql.Row) (*Character, error) {
var c Character
var t string
err := r.Scan(&c.Id, &c.UserId, &c.Name, &c.Image, &c.StatsJson, &t)
if err != nil {
return nil, err
}
c.DateModified, err = StringToTime(t)
return &c, err
}
示例15: indexExists
func (d oracle) indexExists(mg *Migration, tableName, indexName string) bool {
var row *sql.Row
var name string
query := "SELECT INDEX_NAME FROM USER_INDEXES "
query += "WHERE TABLE_NAME = ? AND INDEX_NAME = ?"
query = d.substituteMarkers(query)
row = mg.Db.QueryRow(query, tableName, indexName)
row.Scan(&name)
return name != ""
}