Read project name from database

This commit is contained in:
Siegfried Siegert 2020-09-20 17:53:48 +02:00
parent e02af3c353
commit dc5d066698

View File

@ -29,6 +29,7 @@ func (db *DB) AllDevices() ([]*Device, error) {
if err != nil {
return nil, err
}
device.ProjectName, err = db.GetProjectName(device.CustomerID)
devices = append(devices, device)
}
if err = rows.Err(); err != nil {
@ -56,3 +57,26 @@ func (db *DB) InsertDevice(device *Device) error {
return err
}
func (db *DB) GetProjectName(projectNumber string) (string, error) {
projectNameRows, err := db.Query("SELECT projectName FROM projects WHERE projectNumber = $1", projectNumber)
if err != nil {
return "", err
}
defer projectNameRows.Close()
projectName := ""
for projectNameRows.Next() {
err := projectNameRows.Scan(&projectName)
if err != nil {
return "", err
}
}
if err = projectNameRows.Err(); err != nil {
return "", err
}
return projectName, err
}