-
Notifications
You must be signed in to change notification settings - Fork 0
/
exists.go
33 lines (27 loc) · 888 Bytes
/
exists.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
// 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 (
"github.com/ainsleyclark/verbis/api/database"
"github.com/ainsleyclark/verbis/api/errors"
"github.com/ainsleyclark/verbis/api/logger"
)
// Exists
//
// Returns a bool indicating if the post cateory exists by ID.
// Logs errors.INTERNAL if there was an error executing the query.
func (s *Store) Exists(id int) bool {
const op = "PostCategoriesStore.Exists"
q := s.Builder().
Select("post_id").
From(s.Schema()+TableName).
Where("post_id", "=", id).
Exists()
var exists bool
err := s.DB().QueryRow(q).Scan(&exists)
if err != nil {
logger.WithError(&errors.Error{Code: errors.INTERNAL, Message: database.ErrQueryMessage, Operation: op, Err: err}).Error()
}
return exists
}