blob: 291562bbea373e4558328332034b7336468f9c95 (
plain) (
tree)
|
|
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
}
|