diff options
Diffstat (limited to 'internal/models/organisations.go')
-rw-r--r-- | internal/models/organisations.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/models/organisations.go b/internal/models/organisations.go index 291562b..edaa992 100644 --- a/internal/models/organisations.go +++ b/internal/models/organisations.go @@ -2,6 +2,7 @@ package models import ( "database/sql" + "errors" "time" ) @@ -32,7 +33,22 @@ func (m *OrganisationModel) Insert(name string) (int, error) { } func (m *OrganisationModel) Get(id int) (Organisation, error) { - return Organisation{}, nil + stmt := `SELECT id, name, created FROM organisations + WHERE id = ?` + + row := m.DB.QueryRow(stmt, id) + + var o Organisation + + err := row.Scan(&o.ID, &o.Name, &o.Created) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return Organisation{}, ErrNoRecord + } else { + return Organisation{}, err + } + } + return o, nil } // Ten most recent... |