diff options
author | Matthew Lemon <y@yulqen.org> | 2024-02-10 12:19:10 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-02-10 12:19:10 +0000 |
commit | c3df229e32a0a50ce4c7b6994e2ed01d6be1e13c (patch) | |
tree | 210c5b468b2cb0c9f8c067085c0f2442f28540f8 /internal | |
parent | 7c4a913645ba1e347ab94097de44eb04d7df4e47 (diff) |
Have added Insert handler for Organisation model
This is a straight forward wrapper around INSERT.
Also added a clientError into a new helpers.go file.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/models/organisations.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/internal/models/organisations.go b/internal/models/organisations.go index 7a8898c..291562b 100644 --- a/internal/models/organisations.go +++ b/internal/models/organisations.go @@ -16,7 +16,19 @@ type OrganisationModel struct { } func (m *OrganisationModel) Insert(name string) (int, error) { - return 0, nil + 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) { |