package api import ( "context" "github.com/tigorlazuardi/bluemage/go/pkg/errs" "github.com/tigorlazuardi/bluemage/go/pkg/telemetry" . "github.com/go-jet/jet/v2/sqlite" . "github.com/tigorlazuardi/bluemage/go/gen/jet/table" ) func (api *API) SubredditExists(ctx context.Context, name string) (exist bool, err error) { ctx, span := tracer.Start(ctx, "SubredditExists") defer func() { telemetry.EndWithStatus(span, err) }() var count int64 stmt := SELECT(COUNT(Subreddits.Name)).WHERE(Subreddits.Name.EQ(String(name))) query, args := stmt.Sql() err = api.DB.QueryRowContext(ctx, query, args...).Scan(&count) if err != nil { err = errs. Wrapw(err, "failed to check subreddit existence", "name", name, "query", stmt.DebugSql(), ) return exist, err } return count > 0, err }