当前位置: 首页>>代码示例>>Golang>>正文


Golang Rows.Scan方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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


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