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