• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang sql.Row类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Row类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:ajiyoshi-vg,项目名称:scannergen,代码行数:33,代码来源:issue.scanner.go


示例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
}
开发者ID:itkpi,项目名称:journey,代码行数:33,代码来源:retrieval.go


示例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
}
开发者ID:ninnemana,项目名称:API,代码行数:30,代码来源:video.go


示例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
}
开发者ID:TheDudeness,项目名称:Chrall,代码行数:25,代码来源:comptestore.go


示例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
}
开发者ID:asta-fulda,项目名称:box,代码行数:32,代码来源:database.go


示例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
}
开发者ID:ninnemana,项目名称:API,代码行数:29,代码来源:applicationGuide.go


示例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
}
开发者ID:stevenroose,项目名称:btcdb,代码行数:37,代码来源:sqlitetx.go


示例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
}
开发者ID:stevenroose,项目名称:btcdb,代码行数:35,代码来源:sqlitetx.go


示例9: consumeRow

func (t *Topic) consumeRow(row *sql.Row) error {
	return row.Scan(
		&t.Id,
		&t.Name,
		&t.CreatedAt,
		&t.UpdatedAt,
	)
}
开发者ID:carrot,项目名称:burrow,代码行数:8,代码来源:topic.go


示例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 != ""
}
开发者ID:hyl87,项目名称:qbs,代码行数:8,代码来源:mysql.go


示例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
}
开发者ID:henriAbel,项目名称:ircbot,代码行数:8,代码来源:database.go


示例12: scanSelectSingle

func scanSelectSingle(m *model.Group, row *sql.Row) error {
	err := row.Scan(
		&m.UID,
		&m.Name,
		&m.UserUID,
		&m.CreatedAt,
	)
	return err
}
开发者ID:gregory90,项目名称:go-user-group,代码行数:9,代码来源:group.go


示例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(
			&notification.ID,
			&notification.Name,
			&created,
			&notified,
			&deleted,
			&oldVulnerabilityNullableID,
			&newVulnerabilityNullableID,
		)

		if err != nil {
			return notification, err
		}
	} else {
		err := row.Scan(&notification.ID, &notification.Name, &created, &notified, &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
}
开发者ID:fatalbanana,项目名称:clair,代码行数:57,代码来源:notification.go


示例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
}
开发者ID:danmondy,项目名称:statshiit,代码行数:10,代码来源:repo.go


示例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 != ""
}
开发者ID:hyl87,项目名称:qbs,代码行数:10,代码来源:oracle.go


示例16: indexExists

func (d postgres) indexExists(mg *Migration, tableName, indexName string) bool {
	var row *sql.Row
	var name string
	query := "SELECT indexname FROM pg_indexes "
	query += "WHERE tablename = ? AND indexname = ?"
	query = d.substituteMarkers(query)
	row = mg.Db.QueryRow(query, tableName, indexName)
	row.Scan(&name)
	return name != ""
}
开发者ID:hyl87,项目名称:qbs,代码行数:10,代码来源:postgres.go


示例17: MapUser

func MapUser(r *sql.Row) (*User, error) {
	var u User
	var t string
	err := r.Scan(&u.Id, &u.Email, &u.Hashword, &u.Rank, &t)
	if err != nil {
		return nil, err
	}
	u.Since, err = StringToTime(t)
	return &u, err
}
开发者ID:danmondy,项目名称:conspire,代码行数:10,代码来源:user.go


示例18: recordFromRow

func recordFromRow(row *sql.Row) (*record, error) {

	rec := new(record)
	err := row.Scan(&rec.name, &rec.salt, &rec.pass, &rec.gid)
	if err != nil {
		return nil, err
	}

	return rec, nil

}
开发者ID:sisatech,项目名称:vprivileges,代码行数:11,代码来源:database.go


示例19: ReadAnimeRow

// ReadAnimeRow Read an Anime object in from a Database Row
func ReadAnimeRow(row *sql.Row) (*models.Anime, error) {
	anime := new(models.Anime)
	err := row.Scan(&anime.ID, &anime.Title, &anime.EnglishTitle, &anime.Description,
		&anime.Episodes, &anime.Score, &anime.Type, &anime.Status,
		&anime.Premiered, &anime.Rank, &anime.Popularity, &anime.StartDate,
		&anime.EndDate, &anime.Favorites, &anime.CreatedAt, &anime.UpdatedAt)
	if err != nil {
		return nil, err
	}
	return anime, err
}
开发者ID:NoworksM,项目名称:listy-api,代码行数:12,代码来源:anime.go


示例20: getMeta

func (self *pgStore) getMeta(key string) (val string, err error) {
	var row *sql.Row
	dbh := self.db

	statement := "select value from meta where key=$1;"
	if row = dbh.QueryRow(statement, key); row != nil {
		row.Scan(&val)
		return val, err
	}
	return "", err
}
开发者ID:michielbdejong,项目名称:FindMyDevice,代码行数:11,代码来源:pg.go



注:本文中的database/sql.Row类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sql.Rows类代码示例发布时间:2022-05-24
下一篇:
Golang sql.Result类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap