diff options
Diffstat (limited to '')
-rw-r--r-- | internal/models/organisations.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/models/organisations.go b/internal/models/organisations.go index edaa992..b765f91 100644 --- a/internal/models/organisations.go +++ b/internal/models/organisations.go @@ -53,5 +53,35 @@ func (m *OrganisationModel) Get(id int) (Organisation, error) { // Ten most recent... func (m *OrganisationModel) Latest() ([]Organisation, error) { + // Pick out the last 10 + stmt := `SELECT id, name, created FROM organisations + ORDER BY id DESC LIMIT 10` + + rows, err := m.DB.Query(stmt) + if err != nil { + return nil, err + } + + defer rows.Close() + + var organisations []Organisation + + for rows.Next() { + var o Organisation + + err = rows.Scan(&o.ID, &o.Name, &o.Created) + if err != nil { + return nil, err + } + + organisations = append(organisations, o) + } + + if err = rows.Err(); err != nil { + return nil, err + } + + return organisations, err + return nil, nil } |