diff --git a/packages/data/db.go b/packages/data/db.go index d15833f..1c4528d 100644 --- a/packages/data/db.go +++ b/packages/data/db.go @@ -283,15 +283,40 @@ func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData, return &data, nil } -// TODO: So nicht mehr nützlich, zeitnah streichen -func (db *DB) GetLastID(i *int64) error { - row := db.QueryRow("SELECT id" + - " FROM " + db.Name + - " ORDER BY id DESC LIMIT 0, 1") +func (db *DB) GetLastID(table string) (int, error) { + var id int - if err := row.Scan(i); err != nil { - return fmt.Errorf("*DB.GetLastID: row.Scan(&i): %v\n", err) + row := db.QueryRow(` + SELECT id + FROM ? + ORDER BY id DESC + LIMIT 0, 1 + `, table) + + if err := row.Scan(&id); err != nil { + return -1, fmt.Errorf("*DB.GetLastID: row.Scan(): %v\n", err) } - return nil + return id, nil +} + +func (db *DB) GetInstructors() (*[]*types.Instructor, error) { + rows, err := db.Query(` + SELECT * + FROM instructors + `) + if err != nil { + return nil, fmt.Errorf("*DB.GetInstructors: db.Query(): %v\n", err) + } + + instructors := make([]*types.Instructor, 0) + for rows.Next() { + instructor := new(types.Instructor) + if err = rows.Scan(instructor); err != nil { + return nil, fmt.Errorf("*DB.GetInstructors: rows.Scan(): %v\n", err) + } + instructors = append(instructors, instructor) + } + + return &instructors, nil }