github.com/Bio-core/jtree@v0.0.0-20190705165106-1d7a7e7d6272/repos/result_repo.go (about) 1 package repos 2 3 import ( 4 "fmt" 5 "log" 6 7 database "github.com/Bio-core/jtree/database" 8 "github.com/Bio-core/jtree/models" 9 ) 10 11 //InsertResult allows users to add generic objects to a collection in the database 12 func InsertResult(result *models.Result) bool { 13 stmt, err := database.DBUpdate.Prepare("INSERT INTO `results`(`failed_regions`,`mean_depth_of_coveage`,`mlpa_pcr`,`mutation`,`overall_hotspots_threshold`,`overall_quality_threshold`,`results_id`,`uid`,`verification_pcr`, `experiment_id`)VALUES(?,?,?,?,?,?,?,?,?,?);") 14 if err != nil { 15 log.Fatal(err) 16 } 17 outcome, err := stmt.Exec( 18 result.FailedRegions, 19 result.MeanDepthOfCoveage, 20 result.MlpaPcr, 21 result.Mutation, 22 result.OverallHotspotsThreshold, 23 result.OverallQualityThreshold, 24 result.ResultsID, 25 result.UID, 26 result.VerificationPcr, 27 result.ExperimentID) 28 stmt.Close() 29 if err != nil { 30 log.Fatal(err, outcome) 31 } 32 return true 33 } 34 35 //GetResultByID gets all and results a list of samples 36 func GetResultByID(ID string) *models.Result { 37 results := []*models.Result{} 38 query := models.Query{} 39 query.SelectedFields = make([]string, 0) 40 query.SelectedFields = append(query.SelectedFields, "*") 41 query.SelectedTables = make([]string, 0) 42 query.SelectedTables = append(query.SelectedTables, "results") 43 query.SelectedCondition = make([][]string, 0) 44 //query.SelectedCondition = append(query.SelectedCondition, make([]string, 0)) 45 conditions := []string{"AND", "results.results_id", "Equal to", ID} 46 query.SelectedCondition = append(query.SelectedCondition, conditions) 47 48 queryString := database.BuildQuery(query) 49 err := database.DBSelect.Select(&results, queryString) 50 if err != nil { 51 fmt.Println(err) 52 return nil 53 } 54 if len(results) == 0 { 55 return nil 56 } 57 return results[0] 58 } 59 60 //UpdateResult allows users to add generic objects to a collection in the database 61 func UpdateResult(result *models.Result) bool { 62 stmt, err := database.DBUpdate.Prepare("UPDATE `results` SET `failed_regions` = ?,`mean_depth_of_coveage` = ?,`mlpa_pcr` = ?,`mutation` = ?,`overall_hotspots_threshold` = ?,`overall_quality_threshold` = ?,`results_id` = ?,`uid` = ?,`verification_pcr` = ?,`experiment_id` = ? WHERE `results_id` = ?;") 63 if err != nil { 64 log.Fatal(err) 65 } 66 outcome, err := stmt.Exec( 67 result.FailedRegions, 68 result.MeanDepthOfCoveage, 69 result.MlpaPcr, 70 result.Mutation, 71 result.OverallHotspotsThreshold, 72 result.OverallQualityThreshold, 73 result.ResultsID, 74 result.UID, 75 result.VerificationPcr, 76 result.ExperimentID, 77 result.ResultsID) 78 stmt.Close() 79 if err != nil { 80 log.Fatal(err, outcome) 81 } 82 return true 83 }