summaryrefslogtreecommitdiff
path: root/src/post/post.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2023-01-18 20:15:12 +0100
committerBrian Picciano <mediocregopher@gmail.com>2023-01-18 20:15:12 +0100
commite7b5b55f6718b25a437a891a06a26c21384b6818 (patch)
tree6c95d222f00806e2d3b335bfd0d04c4be34c740f /src/post/post.go
parent4878495914fb9701bedc242eb5087394138c8ee3 (diff)
Add format column to post tables
Diffstat (limited to 'src/post/post.go')
-rw-r--r--src/post/post.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/post/post.go b/src/post/post.go
index 1bdf03e..03326ad 100644
--- a/src/post/post.go
+++ b/src/post/post.go
@@ -34,6 +34,7 @@ type Post struct {
Tags []string // only alphanumeric supported
Series string
Body string
+ Format Format
}
// StoredPost is a Post which has been stored in a Store, and has been given
@@ -103,22 +104,24 @@ func (s *store) Set(post Post, now time.Time) (bool, error) {
_, err := tx.Exec(
`INSERT INTO posts (
- id, title, description, series, published_at, body
+ id, title, description, series, published_at, body, format
)
VALUES
- (?, ?, ?, ?, ?, ?)
+ (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
title=excluded.title,
description=excluded.description,
series=excluded.series,
last_updated_at=?,
- body=excluded.body`,
+ body=excluded.body,
+ format=excluded.format`,
post.ID,
post.Title,
&sql.NullString{String: post.Description, Valid: len(post.Description) > 0},
&sql.NullString{String: post.Series, Valid: post.Series != ""},
nowSQL,
post.Body,
+ post.Format,
nowSQL,
)
@@ -174,8 +177,7 @@ func (s *store) get(
query := `
SELECT
p.id, p.title, p.description, p.series, GROUP_CONCAT(pt.tag),
- p.published_at, p.last_updated_at,
- p.body
+ p.published_at, p.last_updated_at, p.body, p.format
FROM posts p
LEFT JOIN post_tags pt ON (p.id = pt.post_id)
` + where + `
@@ -208,8 +210,7 @@ func (s *store) get(
err := rows.Scan(
&post.ID, &post.Title, &description, &series, &tag,
- &publishedAt, &lastUpdatedAt,
- &post.Body,
+ &publishedAt, &lastUpdatedAt, &post.Body, &post.Format,
)
if err != nil {