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 }
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 }
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 }
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 }