|
|
|
@ -96,7 +96,7 @@ func (s *store) Set(post Post, now time.Time) (bool, error) { |
|
|
|
|
|
|
|
|
|
var first bool |
|
|
|
|
|
|
|
|
|
err := s.db.withTx(func(tx *sql.Tx) error { |
|
|
|
|
err := s.db.WithTx(func(tx *sql.Tx) error { |
|
|
|
|
|
|
|
|
|
nowTS := now.Unix() |
|
|
|
|
|
|
|
|
@ -244,7 +244,7 @@ func (s *store) get( |
|
|
|
|
|
|
|
|
|
func (s *store) Get(page, count int) ([]StoredPost, bool, error) { |
|
|
|
|
|
|
|
|
|
posts, err := s.get(s.db.db, count+1, page*count, ``) |
|
|
|
|
posts, err := s.get(s.db, count+1, page*count, ``) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
return nil, false, fmt.Errorf("querying posts: %w", err) |
|
|
|
@ -262,7 +262,7 @@ func (s *store) Get(page, count int) ([]StoredPost, bool, error) { |
|
|
|
|
|
|
|
|
|
func (s *store) GetByID(id string) (StoredPost, error) { |
|
|
|
|
|
|
|
|
|
posts, err := s.get(s.db.db, 0, 0, `WHERE p.id=?`, id) |
|
|
|
|
posts, err := s.get(s.db, 0, 0, `WHERE p.id=?`, id) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
return StoredPost{}, fmt.Errorf("querying posts: %w", err) |
|
|
|
@ -280,14 +280,14 @@ func (s *store) GetByID(id string) (StoredPost, error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *store) GetBySeries(series string) ([]StoredPost, error) { |
|
|
|
|
return s.get(s.db.db, 0, 0, `WHERE p.series=?`, series) |
|
|
|
|
return s.get(s.db, 0, 0, `WHERE p.series=?`, series) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *store) GetByTag(tag string) ([]StoredPost, error) { |
|
|
|
|
|
|
|
|
|
var posts []StoredPost |
|
|
|
|
|
|
|
|
|
err := s.db.withTx(func(tx *sql.Tx) error { |
|
|
|
|
err := s.db.WithTx(func(tx *sql.Tx) error { |
|
|
|
|
|
|
|
|
|
rows, err := tx.Query(`SELECT post_id FROM post_tags WHERE tag = ?`, tag) |
|
|
|
|
|
|
|
|
@ -331,7 +331,7 @@ func (s *store) GetByTag(tag string) ([]StoredPost, error) { |
|
|
|
|
|
|
|
|
|
func (s *store) GetTags() ([]string, error) { |
|
|
|
|
|
|
|
|
|
rows, err := s.db.db.Query(`SELECT tag FROM post_tags GROUP BY tag`) |
|
|
|
|
rows, err := s.db.Query(`SELECT tag FROM post_tags GROUP BY tag`) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("querying all tags: %w", err) |
|
|
|
|
} |
|
|
|
@ -355,7 +355,7 @@ func (s *store) GetTags() ([]string, error) { |
|
|
|
|
|
|
|
|
|
func (s *store) Delete(id string) error { |
|
|
|
|
|
|
|
|
|
return s.db.withTx(func(tx *sql.Tx) error { |
|
|
|
|
return s.db.WithTx(func(tx *sql.Tx) error { |
|
|
|
|
|
|
|
|
|
if _, err := tx.Exec(`DELETE FROM post_tags WHERE post_id = ?`, id); err != nil { |
|
|
|
|
return fmt.Errorf("deleting from post_tags: %w", err) |
|
|
|
|