Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 15, 2021 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/4de1357bb1afb45458d445e044ff9f1e to your computer and use it in GitHub Desktop.
Save parzibyte/4de1357bb1afb45458d445e044ff9f1e to your computer and use it in GitHub Desktop.
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