summaryrefslogblamecommitdiffstats
path: root/internal/models/organisations.go
blob: 291562bbea373e4558328332034b7336468f9c95 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                              












                                                          









                                                               
package models

import (
	"database/sql"
	"time"
)

type Organisation struct {
	ID      int
	Name    string
	Created time.Time
}

type OrganisationModel struct {
	DB *sql.DB
}

func (m *OrganisationModel) Insert(name string) (int, error) {
	stmt := `INSERT INTO organisations (name, created)
            VALUEs (?, UTC_TIMESTAMP())`

	result, err := m.DB.Exec(stmt, name)
	if err != nil {
		return 0, err
	}

	id, err := result.LastInsertId()
	if err != nil {
		return 0, err
	}
	return int(id), nil
}

func (m *OrganisationModel) Get(id int) (Organisation, error) {
	return Organisation{}, nil
}

// Ten most recent...
func (m *OrganisationModel) Latest() ([]Organisation, error) {
	return nil, nil
}