-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
34 lines (28 loc) · 1.03 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2020 The Verbis Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package categories
import (
"database/sql"
"fmt"
"github.com/ainsleyclark/verbis/api/database"
"github.com/ainsleyclark/verbis/api/errors"
)
// update
//
// Returns nil if there was no error updating.
// Returns errors.INTERNAL if the SQL query was invalid or the function could not obtain the newly created ID.
func (s *Store) update(postID, catID int) error {
const op = "PostCategoriesStore.Create"
q := s.Builder().
Update(s.Schema()+TableName).
Column("category_id", catID).
Where("post_id", "=", postID)
_, err := s.DB().Exec(q.Build())
if err == sql.ErrNoRows {
return &errors.Error{Code: errors.INTERNAL, Message: fmt.Sprintf("Error updating post category with the post ID: %d", postID), Operation: op, Err: err}
} else if err != nil {
return &errors.Error{Code: errors.INTERNAL, Message: database.ErrQueryMessage, Operation: op, Err: err}
}
return nil
}