/
post_content.go
43 lines (36 loc) · 1.16 KB
/
post_content.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
35
36
37
38
39
40
41
42
43
package datastore
import (
"context"
"database/sql"
"github.com/pkg/errors"
"github.com/lib/pq"
"github.com/nedrocks/delphisbe/graph/model"
"github.com/sirupsen/logrus"
)
func (d *delphisDB) PutPostContent(ctx context.Context, tx *sql.Tx, postContent model.PostContent) error {
logrus.Debug("PutPostContent::SQL Create")
if err := d.initializeStatements(ctx); err != nil {
logrus.WithError(err).Error("PutPostContent::failed to initialize statements")
return err
}
_, err := tx.StmtContext(ctx, d.prepStmts.putPostContentsStmt).ExecContext(
ctx,
postContent.ID,
postContent.Content,
pq.Array(postContent.MentionedEntities),
)
if err != nil {
logrus.WithError(err).Error("failed to execute putPostContentsStmt")
return errors.Wrap(err, "failed to put postContents")
}
return nil
}
func (d *delphisDB) GetPostContentByID(ctx context.Context, id string) (*model.PostContent, error) {
logrus.Debug("GetPostContentByID::SQL Query")
found := model.PostContent{}
if err := d.sql.First(&found, &model.PostContent{ID: id}).Error; err != nil {
logrus.WithError(err).Errorf("Failed to get PostContent by ID")
return nil, err
}
return &found, nil
}