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


Golang Tx.Query方法代码示例

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


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

示例1: fetchRunSetSummaries

func fetchRunSetSummaries(database *pgx.Tx, machine string, config string) ([]RunSetSummary, *requestError) {
	rows, err := database.Query("queryRunSetSummaries", machine, config)
	if err != nil {
		return nil, internalServerError("Could not fetch run set summaries")
	}
	var summaries []RunSetSummary
	for rows.Next() {
		var rss RunSetSummary
		if err = rows.Scan(&rss.ID, &rss.MainProduct.Commit); err != nil {
			return nil, internalServerError("Could not scan run set summary")
		}
		summaries = append(summaries, rss)
	}
	return summaries, nil
}
开发者ID:xamarin,项目名称:benchmarker,代码行数:15,代码来源:db.go

示例2: insertResults

func insertResults(database *pgx.Tx, runID int32, results Results, update bool) *requestError {
	idByMetric := make(map[string]int32)
	if update {
		rows, err := database.Query("queryRunMetricsForRun", runID)
		if err != nil {
			return internalServerError("Could not query run metrics")
		}
		for rows.Next() {
			var runMetricID int32
			var metric string
			err = rows.Scan(&runMetricID, &metric)
			if err != nil {
				return internalServerError("Could not scan run metric")
			}
			idByMetric[metric] = runMetricID
		}
	}

	for m, v := range results {
		var err error
		runMetricID, exists := idByMetric[m]
		if metricIsArray(m) {
			var arr []float64
			for _, x := range v.([]interface{}) {
				arr = append(arr, x.(float64))
			}
			if exists {
				_, err = database.Exec("updateRunMetricArray", runMetricID, arr)
			} else {
				_, err = database.Exec("insertRunMetricArray", runID, m, arr)
			}
		} else {
			if exists {
				_, err = database.Exec("updateRunMetricNumber", runMetricID, v)
			} else {
				_, err = database.Exec("insertRunMetricNumber", runID, m, v)
			}
		}
		if err != nil {
			fmt.Printf("run metric insert error: %s\n", err)
			return internalServerError("Could not insert run metric")
		}
	}
	return nil
}
开发者ID:xamarin,项目名称:benchmarker,代码行数:45,代码来源:db.go

示例3: fetchBenchmarks

func fetchBenchmarks(database *pgx.Tx) (map[string]bool, *requestError) {
	rows, err := database.Query("queryBenchmarks")
	if err != nil {
		return nil, internalServerError("Could not get benchmarks")
	}
	defer rows.Close()

	names := make(map[string]bool)
	for rows.Next() {
		var name string
		if err = rows.Scan(&name); err != nil {
			return nil, internalServerError("Could not scan benchmark name")
		}
		names[name] = true
	}

	return names, nil
}
开发者ID:xamarin,项目名称:benchmarker,代码行数:18,代码来源:db.go

示例4: fetchRunSet

func fetchRunSet(database *pgx.Tx, id int32, withRuns bool) (*RunSet, *requestError) {
	var rs RunSet
	var secondaryCommits []string
	var pullRequestID *int32
	err := database.QueryRow("queryRunSet", id).Scan(&rs.StartedAt, &rs.FinishedAt,
		&rs.BuildURL, &rs.LogURLs,
		&rs.MainProduct.Commit, &secondaryCommits, &rs.Machine.Name, &rs.Config.Name,
		&rs.TimedOutBenchmarks, &rs.CrashedBenchmarks,
		&pullRequestID)
	if err == pgx.ErrNoRows {
		return nil, badRequestError("Run set does not exist")
	}
	if err != nil {
		fmt.Printf("run set query error: %s\n", err.Error())
		return nil, internalServerError("Could not get run set")
	}

	// FIXME: combine these two queries with the above one
	err = database.QueryRow("queryCommit", rs.MainProduct.Commit).Scan(&rs.MainProduct.Name)
	if err != nil {
		return nil, internalServerError("Could not get commit")
	}

	for _, c := range secondaryCommits {
		product := Product{Commit: c}
		err = database.QueryRow("queryCommit", c).Scan(&product.Name)
		if err != nil {
			return nil, internalServerError("Could not get commit")
		}

		rs.SecondaryProducts = append(rs.SecondaryProducts, product)
	}

	err = database.QueryRow("queryMachine", rs.Machine.Name).Scan(&rs.Machine.Architecture)
	if err != nil {
		return nil, internalServerError("Could not get machine")
	}

	config, reqErr := fetchConfig(database, rs.Config.Name)
	if reqErr != nil {
		return nil, nil
	}

	rs.Config = *config

	if withRuns {
		rows, err := database.Query("queryRunMetrics", id)
		if err != nil {
			return nil, internalServerError("Could not get run metrics")
		}
		defer rows.Close()

		runs := make(map[int32]*Run)

		for rows.Next() {
			var runID int32
			var benchmark string
			var metric string
			var resultNumber *float64
			var resultArray []float64

			if err = rows.Scan(&runID, &benchmark, &metric, &resultNumber, &resultArray); err != nil {
				return nil, internalServerError("Could not scan run metric: " + err.Error())
			}

			var resultValue interface{}
			if metricIsArray(metric) {
				resultValue = resultArray
			} else if resultNumber != nil {
				resultValue = *resultNumber
			} else {
				return nil, internalServerError("Run metric data is inconsistent")
			}

			run := runs[runID]
			if run == nil {
				run = &Run{Benchmark: benchmark, Results: make(map[string]interface{})}
				runs[runID] = run
			}

			run.Results[metric] = resultValue
		}

		for _, r := range runs {
			rs.Runs = append(rs.Runs, *r)
		}
	}

	return &rs, nil
}
开发者ID:xamarin,项目名称:benchmarker,代码行数:90,代码来源:db.go


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