Read project name from database
This commit is contained in:
parent
e02af3c353
commit
dc5d066698
@ -29,6 +29,7 @@ func (db *DB) AllDevices() ([]*Device, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
device.ProjectName, err = db.GetProjectName(device.CustomerID)
|
||||||
devices = append(devices, device)
|
devices = append(devices, device)
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
@ -56,3 +57,26 @@ func (db *DB) InsertDevice(device *Device) error {
|
|||||||
|
|
||||||
return err
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user