From 7872296b838f4d1b26c6a0a01d79d27fe5ab44cc Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 15 Apr 2023 21:07:16 +0200 Subject: Move asset store into its own package --- src/post/post.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/post/post.go') diff --git a/src/post/post.go b/src/post/post.go index 03326ad..9c8f0cf 100644 --- a/src/post/post.go +++ b/src/post/post.go @@ -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) -- cgit v1.2.3