Skip to content

Commit

Permalink
feat: change to new sql schema
Browse files Browse the repository at this point in the history
  • Loading branch information
phuchptty committed Jan 14, 2024
1 parent 8941264 commit dc1dcfd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modules/converter/tsv2sql/tsv2sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func convertStudents(inputPath string, outputPath string) {
sqlCommands := make([]string, 0)

for _, student := range tsvContent {
sqlCommand := fmt.Sprintf("INSERT INTO Students (Id,Name, Class) VALUES (\"%s\", \"%s\", \"%s\") ON DUPLICATE KEY UPDATE Name=\"%s\",Class=\"%s\";",
sqlCommand := fmt.Sprintf("INSERT INTO students (id,name, class) VALUES (\"%s\", \"%s\", \"%s\") "+
"ON DUPLICATE KEY UPDATE name=\"%s\",class=\"%s\";",
student.StudentCode, student.StudentName, student.StudentClass, student.StudentName, student.StudentClass)
sqlCommands = append(sqlCommands, sqlCommand)
}
Expand Down Expand Up @@ -103,8 +104,8 @@ func convertSubjects(inputPath string, outputPath string) {
sqlCommands := make([]string, 0)

for _, items := range tsvContent {
sqlCommand := fmt.Sprintf("INSERT INTO Subjects (Id,Name,NumberOfCredits) VALUES (\"%s\", \"%s\", %s) "+
"ON DUPLICATE KEY UPDATE Name=\"%s\",NumberOfCredits=%s;",
sqlCommand := fmt.Sprintf("INSERT INTO subjects (id,name,numberOfCredits) VALUES (\"%s\", \"%s\", %s) "+
"ON DUPLICATE KEY UPDATE name=\"%s\",numberOfCredits=%s;",
items.SubjectCode, items.SubjectName, items.SubjectCredit, items.SubjectName, items.SubjectCredit)
sqlCommands = append(sqlCommands, sqlCommand)
}
Expand Down Expand Up @@ -135,11 +136,11 @@ func convertScores(inputPath string, outputPath string) {
sqlCommands := make([]string, 0)

for _, items := range tsvContent {
sqlCommand := fmt.Sprintf("INSERT INTO Scores "+
"(StudentId,SubjectId,FirstComponentScore,SecondComponentScore,ExamScore,AvgScore,AlphabetScore) "+
sqlCommand := fmt.Sprintf("INSERT INTO scores "+
"(studentId,subjectId,firstComponentScore,secondComponentScore,examScore,averageScore,alphabetScore) "+
"VALUES (\"%s\", \"%s\", %.1f, %.1f, %.1f ,%.1f, \"%s\") "+
"ON DUPLICATE KEY UPDATE "+
"FirstComponentScore=%.f,SecondComponentScore=%.f,ExamScore=%.1f,AvgScore=%.1f,AlphabetScore=\"%s\";",
"firstComponentScore=%.f,secondComponentScore=%.f,examScore=%.1f,averageScore=%.1f,alphabetScore=\"%s\";",
items.StudentCode, items.SubjectCode, items.StudentScoreTP1, items.StudentScoreTP2, items.StudentScoreExam,
items.StudentScoreFinal, items.StudentScoreStr, items.StudentScoreTP1, items.StudentScoreTP2,
items.StudentScoreExam, items.StudentScoreFinal, items.StudentScoreStr)
Expand Down

0 comments on commit dc1dcfd

Please sign in to comment.