示例#1
1
func getApplicationDeployments(db *sql.DB, a *models.Application, limit int) ([]*models.Deployment, error) {
	deployments := []*models.Deployment{}

	rows, err := db.Query(applicationDeploymentsStmt, a.Name, limit)
	if err != nil {
		return deployments, err
	}
	defer rows.Close()

	for rows.Next() {
		var state string
		d := &models.Deployment{}

		err = rows.Scan(&d.Id, &d.UserId, &d.TargetName, &d.CommitSha, &d.Branch, &d.Comment, &state, &d.CreatedAt)
		if err != nil {
			return deployments, err
		}

		d.State = models.DeploymentState(state)

		deployments = append(deployments, d)
	}

	if err := rows.Err(); err != nil {
		return deployments, err
	}

	return deployments, nil
}
示例#2
0
func getDeployment(db *sql.DB, id int) (*models.Deployment, error) {
	d := &models.Deployment{}
	var state string

	err := db.QueryRow(deploymentStmt, id).Scan(&d.Id, &d.UserId, &d.ApplicationName,
		&d.TargetName, &d.CommitSha, &d.Branch, &d.Comment, &state, &d.CreatedAt)
	if err != nil {
		return nil, err
	}

	d.State = models.DeploymentState(state)

	return d, nil
}
示例#3
0
func queryDeploymentRow(db *sql.DB, query string, args ...interface{}) (*models.Deployment, error) {
	d := &models.Deployment{}
	var state string

	err := db.QueryRow(query, args...).Scan(&d.Id, &d.UserId, &d.ApplicationName,
		&d.TargetName, &d.CommitSha, &d.Branch, &d.Comment, &state, &d.CreatedAt)
	if err == sql.ErrNoRows {
		return nil, nil
	}
	if err != nil {
		return nil, err
	}
	d.State = models.DeploymentState(state)

	return d, nil
}
示例#4
0
func readApplicationDeployments(rows *sql.Rows) ([]*models.Deployment, error) {
	deployments := []*models.Deployment{}

	for rows.Next() {
		var state string
		d := &models.Deployment{}

		err := rows.Scan(&d.Id, &d.UserId, &d.TargetName, &d.CommitSha, &d.Branch, &d.Comment, &state, &d.CreatedAt)
		if err != nil {
			return deployments, err
		}

		d.State = models.DeploymentState(state)

		deployments = append(deployments, d)
	}

	if err := rows.Err(); err != nil {
		return deployments, err
	}

	return deployments, nil
}