-
-
Save parzibyte/4de1357bb1afb45458d445e044ff9f1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MateriaConConteoDeTarea struct { | |
Conteo int64 `json:"conteo"` | |
Materia string `json:"materia"` | |
IdMateria string `json:"idMateria"` | |
} | |
func obtenerMateriasConConteoDeTareas(idPeriodo int64) ([]MateriaConConteoDeTarea, error) { | |
materias := []MateriaConConteoDeTarea{} | |
bd, err := obtenerBd() | |
if err != nil { | |
return materias, err | |
} | |
defer bd.Close() | |
rows, err := bd.Raw(`select count(*) AS conteo, | |
materia.nombre AS materia, materia.id AS id_materia from tareas | |
inner join materia on materia.id = tareas.id_materia | |
where id_periodo = ? group by materia.id;`, idPeriodo). | |
Rows() | |
if err != nil { | |
return materias, err | |
} | |
defer rows.Close() | |
for rows.Next() { | |
var m MateriaConConteoDeTarea | |
bd.ScanRows(rows, &m) | |
if err != nil { | |
return materias, err | |
} | |
materias = append(materias, m) | |
} | |
return materias, bd.Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment