postgres

package
v0.46.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func GroupExpr added in v0.24.0

func GroupExpr(g Granularity, col string) string

GroupExpr returns the SQL expression that buckets a column by granularity.

  • GranMonth: "SUBSTRING(col, 1, 7)" → "2024-03"
  • GranWeek: "TO_CHAR(date_trunc(...))" → "2024-03-04" (Monday)

func MomentumFormat added in v0.24.0

func MomentumFormat(g Granularity) string

MomentumFormat returns the TO_CHAR format for momentum date comparison.

func MomentumInterval added in v0.24.0

func MomentumInterval(g Granularity) string

MomentumInterval returns the SQL interval for the rolling momentum window.

func RunSaaSMigrations

func RunSaaSMigrations(db *sql.DB) error

RunSaaSMigrations runs SaaS-specific migrations (tenant tables, RLS policies). Called by devpulse-cloud only, not the self-hosted CLI.

func TrendWindow added in v0.24.0

func TrendWindow(g Granularity) int

TrendWindow returns the number of data points for the moving average.

Types

type DBTX

type DBTX interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

DBTX is the common interface between *sql.DB and *sql.Conn. Both satisfy this interface natively — no adapter needed.

type Granularity added in v0.24.0

type Granularity string

Granularity controls how time-series data is bucketed.

const (
	GranWeek  Granularity = "week"
	GranMonth Granularity = "month"
)

func AutoGranularity added in v0.24.0

func AutoGranularity(days int) Granularity

AutoGranularity selects weekly or monthly grouping based on the time window.

type PoolConfig added in v0.12.3

type PoolConfig struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

PoolConfig controls database connection pool sizing.

func AdminPoolConfig added in v0.12.3

func AdminPoolConfig() PoolConfig

AdminPoolConfig returns minimal pool settings for the admin service.

func DefaultPoolConfig added in v0.12.3

func DefaultPoolConfig() PoolConfig

DefaultPoolConfig returns pool settings suitable for the site service.

func ImportPoolConfig added in v0.12.3

func ImportPoolConfig() PoolConfig

ImportPoolConfig returns smaller pool settings suitable for batch import workers.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements data.Store for PostgreSQL.

func New

func New(dsn string, cfgs ...PoolConfig) (*Store, error)

New creates a new PostgreSQL Store, running migrations automatically. Uses DefaultPoolConfig if no config is provided. DB_MAX_OPEN_CONNS and DB_MAX_IDLE_CONNS env vars override code defaults.

func NewFromConn

func NewFromConn(conn *sql.Conn) *Store

NewFromConn creates a Store backed by a dedicated connection. Used for tenant-scoped requests where RLS requires set_config on a specific connection.

func NewFromEnv

func NewFromEnv(cfgs ...PoolConfig) (*Store, error)

NewFromEnv creates a Store from DATABASE_URL env var, runs base + SaaS migrations. Uses DefaultPoolConfig if no config is provided.

func (*Store) ApplySubstitutions

func (s *Store) ApplySubstitutions(ctx context.Context) ([]*data.Substitution, error)

func (*Store) CleanEntities

func (s *Store) CleanEntities(ctx context.Context) error

func (*Store) ClearState

func (s *Store) ClearState(ctx context.Context, org, repo string) error

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection pool.

func (*Store) ComputeDeepReputation

func (s *Store) ComputeDeepReputation(ctx context.Context, token, username string) (*data.UserReputation, error)

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying *sql.DB for cases that need direct access.

func (*Store) DeleteRepoData

func (s *Store) DeleteRepoData(ctx context.Context, org, repo string) (*data.DeleteResult, error)

func (*Store) EnrichDeveloperEntities added in v0.8.1

func (s *Store) EnrichDeveloperEntities(ctx context.Context, token string) error

EnrichDeveloperEntities fetches full GitHub profiles for developers whose entity is NULL (never enriched) and writes entity back. Developers with no GitHub company get entity=” which marks them as enriched so they are not re-fetched next run.

func (*Store) GetAgingPRs added in v0.15.0

func (s *Store) GetAgingPRs(ctx context.Context, org, repo, entity *string, days int) (*data.AgingPRsSeries, error)

func (*Store) GetAllOrgRepos

func (s *Store) GetAllOrgRepos(ctx context.Context) ([]*data.OrgRepoItem, error)

func (*Store) GetBackfillUntil added in v0.46.0

func (s *Store) GetBackfillUntil(ctx context.Context, org, repo string) (*time.Time, error)

func (*Store) GetChangeFailureRate

func (s *Store) GetChangeFailureRate(ctx context.Context, org, repo, entity *string, days int) (*data.ChangeFailureRateSeries, error)

func (*Store) GetContainerActivity

func (s *Store) GetContainerActivity(ctx context.Context, org, repo *string, days int) (*data.ContainerActivitySeries, error)

func (*Store) GetContributorFunnel

func (s *Store) GetContributorFunnel(ctx context.Context, org, repo, entity *string, days int) (*data.ContributorFunnelSeries, error)

func (*Store) GetContributorMomentum

func (s *Store) GetContributorMomentum(ctx context.Context, org, repo, entity *string, days int) (*data.MomentumSeries, error)

func (*Store) GetContributorProfile

func (s *Store) GetContributorProfile(ctx context.Context, username string, org, repo, entity *string, days int) (*data.ContributorProfileSeries, error)

func (*Store) GetContributorRetention

func (s *Store) GetContributorRetention(ctx context.Context, org, repo, entity *string, days int) (*data.RetentionSeries, error)

func (*Store) GetDailyActivity

func (s *Store) GetDailyActivity(ctx context.Context, org, repo, entity *string, days int) (*data.DailyActivitySeries, error)

func (*Store) GetDataState

func (s *Store) GetDataState(ctx context.Context) (map[string]int64, error)

func (*Store) GetDeveloper

func (s *Store) GetDeveloper(ctx context.Context, username string) (*data.Developer, error)

func (*Store) GetDeveloperPercentages

func (s *Store) GetDeveloperPercentages(ctx context.Context, entity, org, repo *string, ex []string, days int) ([]*data.CountedItem, error)

func (*Store) GetDeveloperUsernames

func (s *Store) GetDeveloperUsernames(ctx context.Context) ([]string, error)

func (*Store) GetEntity

func (s *Store) GetEntity(ctx context.Context, val string) (*data.EntityResult, error)

func (*Store) GetEntityLike

func (s *Store) GetEntityLike(ctx context.Context, query string, limit int) ([]*data.ListItem, error)

func (*Store) GetEntityPercentages

func (s *Store) GetEntityPercentages(ctx context.Context, entity, org, repo *string, ex []string, days int) ([]*data.CountedItem, error)

func (*Store) GetEventTypeSeries

func (s *Store) GetEventTypeSeries(ctx context.Context, org, repo, entity *string, days int) (*data.EventTypeSeries, error)

func (*Store) GetForksAndActivity

func (s *Store) GetForksAndActivity(ctx context.Context, org, repo, entity *string, days int) (*data.ForksAndActivitySeries, error)

func (*Store) GetInsightsSummary

func (s *Store) GetInsightsSummary(ctx context.Context, org, repo, entity *string, days int) (*data.InsightsSummary, error)

func (*Store) GetIssueOpenCloseRatio

func (s *Store) GetIssueOpenCloseRatio(ctx context.Context, org, repo, entity *string, days int) (*data.IssueRatioSeries, error)

func (*Store) GetMaxEventTime added in v0.38.0

func (s *Store) GetMaxEventTime(ctx context.Context, org, repo string) (time.Time, error)

func (*Store) GetMinEventDate

func (s *Store) GetMinEventDate(ctx context.Context, org, repo *string) (string, error)

func (*Store) GetNoFullnameDeveloperUsernames

func (s *Store) GetNoFullnameDeveloperUsernames(ctx context.Context) ([]string, error)

func (*Store) GetOrComputeDeepReputation

func (s *Store) GetOrComputeDeepReputation(ctx context.Context, token, username string) (*data.UserReputation, error)

func (*Store) GetOrgLike

func (s *Store) GetOrgLike(ctx context.Context, query string, limit int) ([]*data.ListItem, error)

func (*Store) GetPRReviewRatio

func (s *Store) GetPRReviewRatio(ctx context.Context, org, repo, entity *string, days int) (*data.PRReviewRatioSeries, error)

func (*Store) GetPRSizeDistribution

func (s *Store) GetPRSizeDistribution(ctx context.Context, org, repo, entity *string, days int) (*data.PRSizeSeries, error)

func (*Store) GetPortfolioSummary added in v0.15.0

func (s *Store) GetPortfolioSummary(ctx context.Context, org, repo *string, days int) (*data.PortfolioSummary, error)

func (*Store) GetReleaseCadence

func (s *Store) GetReleaseCadence(ctx context.Context, org, repo, entity *string, days int) (*data.ReleaseCadenceSeries, error)

func (*Store) GetReleaseDownloads

func (s *Store) GetReleaseDownloads(ctx context.Context, org, repo *string, days int) (*data.ReleaseDownloadsSeries, error)

func (*Store) GetReleaseDownloadsByTag

func (s *Store) GetReleaseDownloadsByTag(ctx context.Context, org, repo *string, days int) (*data.ReleaseDownloadsByTagSeries, error)

func (*Store) GetRepoInsights

func (s *Store) GetRepoInsights(ctx context.Context, org, repo *string) ([]*data.RepoInsights, error)

func (*Store) GetRepoInsightsEventCount added in v0.16.3

func (s *Store) GetRepoInsightsEventCount(ctx context.Context, org, repo string) (int, error)

func (*Store) GetRepoInsightsGeneratedAt

func (s *Store) GetRepoInsightsGeneratedAt(ctx context.Context, org, repo string) (string, error)

func (*Store) GetRepoLike

func (s *Store) GetRepoLike(ctx context.Context, query string, limit int) ([]*data.ListItem, error)

func (*Store) GetRepoMetas

func (s *Store) GetRepoMetas(ctx context.Context, org, repo *string) ([]*data.RepoMeta, error)

func (*Store) GetRepoMetricHistory

func (s *Store) GetRepoMetricHistory(ctx context.Context, org, repo *string, days int) ([]*data.RepoMetricHistory, error)

func (*Store) GetRepoOverview

func (s *Store) GetRepoOverview(ctx context.Context, org *string, days int) ([]*data.RepoOverview, error)

func (*Store) GetReputationComposition added in v0.44.0

func (s *Store) GetReputationComposition(ctx context.Context, org, repo, entity *string, days int) (*data.ReputationComposition, error)

func (*Store) GetResponseSLO added in v0.15.0

func (s *Store) GetResponseSLO(ctx context.Context, org, repo, entity *string, days int) (*data.ResponseSLOSeries, error)

func (*Store) GetReviewLatency

func (s *Store) GetReviewLatency(ctx context.Context, org, repo, entity *string, days int) (*data.ReviewLatencySeries, error)

func (*Store) GetSignals added in v0.15.0

func (s *Store) GetSignals(ctx context.Context, org *string, limit int) ([]*data.Signal, error)

func (*Store) GetState

func (s *Store) GetState(ctx context.Context, query, org, repo string, min time.Time) (*data.State, error)

func (*Store) GetTimeToClose

func (s *Store) GetTimeToClose(ctx context.Context, org, repo, entity *string, days int) (*data.VelocitySeries, error)

func (*Store) GetTimeToFirstResponse

func (s *Store) GetTimeToFirstResponse(ctx context.Context, org, repo, entity *string, days int) (*data.FirstResponseSeries, error)

func (*Store) GetTimeToMerge

func (s *Store) GetTimeToMerge(ctx context.Context, org, repo, entity *string, days int) (*data.VelocitySeries, error)

func (*Store) GetTimeToRestoreBugs

func (s *Store) GetTimeToRestoreBugs(ctx context.Context, org, repo, entity *string, days int) (*data.VelocitySeries, error)

func (*Store) GetUnansweredRate added in v0.15.0

func (s *Store) GetUnansweredRate(ctx context.Context, org, repo, entity *string, days int) (*data.UnansweredSeries, error)

func (*Store) GetUnenrichedDeveloperUsernames added in v0.8.1

func (s *Store) GetUnenrichedDeveloperUsernames(ctx context.Context) ([]string, error)

func (*Store) HasState added in v0.45.7

func (s *Store) HasState(ctx context.Context, org, repo string) (bool, error)

func (*Store) ImportAllContainerVersions

func (s *Store) ImportAllContainerVersions(ctx context.Context, token string) error

func (*Store) ImportAllReleases

func (s *Store) ImportAllReleases(ctx context.Context, token string) error

func (*Store) ImportAllRepoMeta

func (s *Store) ImportAllRepoMeta(ctx context.Context, token string) error

func (*Store) ImportAllRepoMetricHistory

func (s *Store) ImportAllRepoMetricHistory(ctx context.Context, token string) error

func (*Store) ImportContainerVersions

func (s *Store) ImportContainerVersions(ctx context.Context, token, org, repo string) error

func (*Store) ImportDeepReputation

func (s *Store) ImportDeepReputation(ctx context.Context, tokenFn data.TokenFunc, exhaustFn data.ExhaustFunc, limit, staleHours int, org, repo *string) (*data.DeepReputationResult, error)

func (*Store) ImportEvents

func (s *Store) ImportEvents(
	ctx context.Context, tokenFn data.TokenFunc, exhaustFn data.ExhaustFunc,
	owner, repo string, windowStart, windowEnd time.Time,
) (map[string]int, *data.ImportSummary, error)

func (*Store) ImportReleases

func (s *Store) ImportReleases(ctx context.Context, token, owner, repo string) error

func (*Store) ImportRepoMeta

func (s *Store) ImportRepoMeta(ctx context.Context, token, owner, repo string) (time.Time, error)

func (*Store) ImportRepoMetricHistory

func (s *Store) ImportRepoMetricHistory(ctx context.Context, token, owner, repo string) error

func (*Store) ImportReputation

func (s *Store) ImportReputation(ctx context.Context, org, repo *string) (*data.ReputationResult, error)

func (*Store) QueryEntities

func (s *Store) QueryEntities(ctx context.Context, val string, limit int) ([]*data.CountedItem, error)

func (*Store) SaveAndApplyDeveloperSub

func (s *Store) SaveAndApplyDeveloperSub(ctx context.Context, prop, old, new string) (*data.Substitution, error)

func (*Store) SaveBackfillUntil added in v0.46.0

func (s *Store) SaveBackfillUntil(ctx context.Context, org, repo string, until time.Time) error

func (*Store) SaveDevelopers

func (s *Store) SaveDevelopers(ctx context.Context, devs []*data.Developer) error

func (*Store) SaveRepoInsights

func (s *Store) SaveRepoInsights(ctx context.Context, org, repo string, ri *data.RepoInsights) error

func (*Store) SaveState

func (s *Store) SaveState(ctx context.Context, query, org, repo string, state *data.State) error

func (*Store) SearchDeveloperUsernames

func (s *Store) SearchDeveloperUsernames(ctx context.Context, query string, org, repo *string, days, limit int) ([]string, error)

func (*Store) SearchDevelopers

func (s *Store) SearchDevelopers(ctx context.Context, val string, limit int) ([]*data.DeveloperListItem, error)

func (*Store) SearchEvents

func (s *Store) SearchEvents(ctx context.Context, q *data.EventSearchCriteria) ([]*data.EventDetails, error)

func (*Store) UpdateDeveloperNames

func (s *Store) UpdateDeveloperNames(ctx context.Context, devs map[string]string) error

func (*Store) UpdateEvents

func (s *Store) UpdateEvents(ctx context.Context, token string, concurrency int) (map[string]int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL