feat: add CountPostsOfSite query and DB method

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Leon Mika 2026-03-22 14:30:57 +11:00
parent 9919f3444a
commit 5bf77ede5c
4 changed files with 82 additions and 0 deletions

View file

@ -9,6 +9,28 @@ import (
"context"
)
const countPostsOfSite = `-- name: CountPostsOfSite :one
SELECT COUNT(*) FROM posts
WHERE site_id = ?1 AND (
CASE CAST (?2 AS TEXT)
WHEN 'deleted' THEN deleted_at > 0
ELSE deleted_at = 0
END
)
`
type CountPostsOfSiteParams struct {
SiteID int64
PostFilter string
}
func (q *Queries) CountPostsOfSite(ctx context.Context, arg CountPostsOfSiteParams) (int64, error) {
row := q.db.QueryRowContext(ctx, countPostsOfSite, arg.SiteID, arg.PostFilter)
var count int64
err := row.Scan(&count)
return count, err
}
const hardDeletePost = `-- name: HardDeletePost :exec
DELETE FROM posts WHERE id = ?
`