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

Golang pgx.Rows类代码示例

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

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



在下文中一共展示了Rows类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetPeersFromRows

func GetPeersFromRows(rows *pgx.Rows) (peers []Peer, err error) {
	for rows.Next() {
		var (
			id       int32
			peerId   []byte
			ip       string
			port     int32
			infoHash []byte
			isIpV6   bool
		)

		err = rows.Scan(&id, &peerId, &ip, &port, &infoHash, &isIpV6)
		if err != nil {
			log.Print(err)
			return peers, err
		}

		peer := new(Peer)
		peer.Id = id
		peer.PeerId = peerId
		peer.Ip = ip
		peer.Port = port
		peer.InfoHash = infoHash
		peer.IsIpV6 = isIpV6

		peers = append(peers, *peer)
	}

	return peers, err
}
开发者ID:bpina,项目名称:go-tracker,代码行数:30,代码来源:peer.go


示例2: FindByKeys

func (s *ValueStore) FindByKeys(dto *models.ValueDTO, mode string) (res []models.Value, err error) {
	if err := models.V.StructPartial(dto, "Keys"); err != nil {
		return nil, err
	}

	if _, exist := map[string]bool{
		"&&": true,
		"@>": true,
		"=":  true,
	}[mode]; !exist {
		mode = "="
	}

	model := models.NewValue()
	model.TransformFrom(dto)

	fields, modelValues := model.Fields()

	query := SqlSelect(model.TableName(), fields)
	// any - "&&", contains - "@>"", equal - "="
	if mode == "=" {
		query += fmt.Sprintf(" WHERE sort_text_array(keys) %s sort_text_array(?) AND is_removed = false", mode)
	} else {
		query += fmt.Sprintf(" WHERE keys %s ? AND is_removed = false", mode)
	}

	query = FormateToPQuery(query)

	var rows *pgx.Rows

	if dto.Tx != nil {
		rows, err = dto.Tx.Query(query, model.Keys)
	} else {
		rows, err = s.db.Query(query, model.Keys)
	}

	defer rows.Close()

	if err != nil {
		s.ErrorLog("action", "поиск записей по keys", "err", err, "keys", model.Keys)
		return
	}

	for rows.Next() {
		if err = rows.Scan(modelValues...); err != nil {
			s.ErrorLog("action", "поиск записей по keys", "subaction", "сканирование строки", "err", err, "keys", model.Keys)
			return
		}

		// res = append(res, *model)
		_model := models.NewValue()
		_model.TransformFrom(model)
		res = append(res, *_model)

		// TODO: reset for maps
		model.Value = models.InterfaceMap{}
	}

	return res, nil
}
开发者ID:gebv,项目名称:magickeys,代码行数:60,代码来源:store_values.go


示例3: GetTorrentsFromRows

func GetTorrentsFromRows(rows *pgx.Rows) (torrents []Torrent, err error) {
	for rows.Next() {
		var (
			info_hash  []byte
			complete   int32
			incomplete int32
		)

		err = rows.Scan(&info_hash, &incomplete, &complete)

		if err != nil {
			return torrents, err
		}

		torrent := new(Torrent)
		torrent.InfoHash = info_hash
		torrent.Complete = complete
		torrent.Incomplete = incomplete

		torrents = append(torrents, *torrent)
	}

	return torrents, err
}
开发者ID:bpina,项目名称:go-tracker,代码行数:24,代码来源:torrent.go


示例4: releaseList

func releaseList(rows *pgx.Rows) ([]*ct.Release, error) {
	var releases []*ct.Release
	for rows.Next() {
		release, err := scanRelease(rows)
		if err != nil {
			rows.Close()
			return nil, err
		}
		releases = append(releases, release)
	}
	return releases, rows.Err()
}
开发者ID:ably-forks,项目名称:flynn,代码行数:12,代码来源:release.go


示例5: scanFormations

func scanFormations(rows *pgx.Rows) ([]*ct.Formation, error) {
	var formations []*ct.Formation
	for rows.Next() {
		formation, err := scanFormation(rows)
		if err != nil {
			rows.Close()
			return nil, err
		}
		formations = append(formations, formation)
	}
	return formations, rows.Err()
}
开发者ID:imjorge,项目名称:flynn,代码行数:12,代码来源:formation.go


示例6: listExpanded

func (r *FormationRepo) listExpanded(rows *pgx.Rows) ([]*ct.ExpandedFormation, error) {
	defer rows.Close()

	var formations []*ct.ExpandedFormation

	// artifactIDs is a list of artifact IDs related to the formation list
	// and is used to populate the formation's artifact fields using a
	// subsequent artifact list query
	artifactIDs := make(map[string]struct{})

	for rows.Next() {
		formation, err := scanExpandedFormation(rows)
		if err != nil {
			return nil, err
		}
		formations = append(formations, formation)

		for _, id := range formation.Release.ArtifactIDs {
			artifactIDs[id] = struct{}{}
		}
	}

	if len(artifactIDs) > 0 {
		ids := make([]string, 0, len(artifactIDs))
		for id := range artifactIDs {
			ids = append(ids, id)
		}
		artifacts, err := r.artifacts.ListIDs(ids...)
		if err != nil {
			return nil, err
		}
		for _, formation := range formations {
			populateFormationArtifacts(formation, artifacts)
		}
	}

	return formations, rows.Err()
}
开发者ID:imjorge,项目名称:flynn,代码行数:38,代码来源:formation.go


示例7: fetch_task

// returns true if a task has been processed
func fetch_task() (bool, error) {
	var err error
	var rows *pgx.Rows

	if rows, err = db.Query(fetchQuery, fetchQueryArgs...); err != nil {
		return false, fmt.Errorf("Could not query for tasks: ", err.Error())
	}

	if rows.Next() {
		var task_id int64
		var worker string
		var parameters []byte

		if err := rows.Scan(&task_id, &worker, &parameters); err != nil {
			rows.Close()
			return false, fmt.Errorf("Could not retrieve columns: ", err.Error())
		}

		rows.Close()

		log.Println("Starting worker:", worker)
		status, result := work(worker, parameters)
		log.Println("Result:", status)

		if _, err := db.Exec(`UPDATE `+quotedTableName+` SET status=$2,result=$3,end_time=now() WHERE task_id=$1`, task_id, status, result); err != nil {
			return false, fmt.Errorf("Could not update task: ", err.Error())
		}
	} else {
		rows.Close()
		return false, nil
	}

	return true, nil
}
开发者ID:debackerl,项目名称:pgturtle,代码行数:35,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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