From e7b5b55f6718b25a437a891a06a26c21384b6818 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Wed, 18 Jan 2023 20:15:12 +0100 Subject: Add format column to post tables --- src/post/post.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/post/post.go') 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 { -- cgit v1.2.3