sqlc

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcquireMessagesByTopicParams

type AcquireMessagesByTopicParams struct {
	Topic string      `json:"topic"`
	Limit pgtype.Int4 `json:"limit"`
}

type ClaimMaintenanceLeasesParams added in v0.3.0

type ClaimMaintenanceLeasesParams struct {
	HolderID    uuid.UUID          `json:"holder_id"`
	Topics      []string           `json:"topics"`
	StaleCutoff pgtype.Timestamptz `json:"stale_cutoff"`
}

type ConsumerSession added in v0.3.0

type ConsumerSession struct {
	ConsumerID                 uuid.UUID          `json:"consumer_id"`
	ExpiresAt                  pgtype.Timestamptz `json:"expires_at"`
	MaintainsDefaultExpiration bool               `json:"maintains_default_expiration"`
}

type CountLiveConsumerSessionsRow added in v0.3.0

type CountLiveConsumerSessionsRow struct {
	Live               int64 `json:"live"`
	DefaultMaintainers int64 `json:"default_maintainers"`
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

type DeleteExpiredMessagesParams added in v0.2.0

type DeleteExpiredMessagesParams struct {
	Topic  string             `json:"topic"`
	Cutoff pgtype.Timestamptz `json:"cutoff"`
}

type DeleteMessagesByIdsParams

type DeleteMessagesByIdsParams struct {
	Topic string  `json:"topic"`
	Ids   []int64 `json:"ids"`
}

type GetMaintenanceCandidateTopicsParams added in v0.3.0

type GetMaintenanceCandidateTopicsParams struct {
	HolderID               uuid.UUID          `json:"holder_id"`
	StaleCutoff            pgtype.Timestamptz `json:"stale_cutoff"`
	DefaultExpirationNanos pgtype.Int8        `json:"default_expiration_nanos"`
	IncludeTopics          []string           `json:"include_topics"`
	SlackSeconds           float64            `json:"slack_seconds"`
}

type GetMaintenanceCandidateTopicsRow added in v0.3.0

type GetMaintenanceCandidateTopicsRow struct {
	Topic           string      `json:"topic"`
	ExpirationNanos pgtype.Int8 `json:"expiration_nanos"`
	HeldByMe        bool        `json:"held_by_me"`
	Unleased        bool        `json:"unleased"`
	LeaseExpired    bool        `json:"lease_expired"`
}

type GetTopicForUpdateRow added in v0.2.0

type GetTopicForUpdateRow struct {
	ExclusiveConsumerID        *uuid.UUID         `json:"exclusive_consumer_id"`
	ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}

type GetTopicsWithExpirationRow added in v0.3.0

type GetTopicsWithExpirationRow struct {
	Topic                      string             `json:"topic"`
	ExpirationNanos            pgtype.Int8        `json:"expiration_nanos"`
	ExclusiveConsumerID        *uuid.UUID         `json:"exclusive_consumer_id"`
	ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}

type InsertMaintenanceLeaseIfAbsentParams added in v0.2.0

type InsertMaintenanceLeaseIfAbsentParams struct {
	Topic    string    `json:"topic"`
	HolderID uuid.UUID `json:"holder_id"`
}

type InsertMaintenanceLeasesParams added in v0.3.0

type InsertMaintenanceLeasesParams struct {
	Topics   []string  `json:"topics"`
	HolderID uuid.UUID `json:"holder_id"`
}

type InsertMessageParams

type InsertMessageParams struct {
	Topic   string `json:"topic"`
	Payload []byte `json:"payload"`
}

type InsertTopicIfAbsentParams added in v0.2.0

type InsertTopicIfAbsentParams struct {
	Topic           string      `json:"topic"`
	ExpirationNanos pgtype.Int8 `json:"expiration_nanos"`
}

type MaintenanceLease added in v0.2.0

type MaintenanceLease struct {
	Topic      string             `json:"topic"`
	HolderID   uuid.UUID          `json:"holder_id"`
	AcquiredAt pgtype.Timestamptz `json:"acquired_at"`
}

type Message

type Message struct {
	ID         int64              `json:"id"`
	InsertedAt pgtype.Timestamptz `json:"inserted_at"`
	Topic      string             `json:"topic"`
	Payload    []byte             `json:"payload"`
}

type Queries

type Queries struct {
}

func New

func New() *Queries

func (*Queries) AcquireMessagesByTopic

func (q *Queries) AcquireMessagesByTopic(ctx context.Context, db DBTX, arg AcquireMessagesByTopicParams) ([]*Message, error)

func (*Queries) BumpTopicActivityIfStale added in v0.3.0

func (q *Queries) BumpTopicActivityIfStale(ctx context.Context, db DBTX, topic string) error

Flush-path counterpart of the insert trigger's activity bump. The trigger bumps with FOR UPDATE SKIP LOCKED, and ProcessMessages holds the topic row lock for its whole transaction — so on a continuously-processed topic the trigger can be starved out of every bump. The flush transaction already holds that lock, so it compensates by bumping here after processing messages, gated to the same 30-second granularity as the trigger.

func (*Queries) ClaimMaintenanceLeases added in v0.3.0

func (q *Queries) ClaimMaintenanceLeases(ctx context.Context, db DBTX, arg ClaimMaintenanceLeasesParams) ([]string, error)

Takeover path for lease rows whose holder is gone: its session lapsed, or (pre-session holder) its acquired_at went stale. SKIP LOCKED lets racing claimants skip contested rows instead of queueing; the loser claims other topics on its next scan. consumer_sessions (the small side, kept small by the retention sweep) is narrowed once into a MATERIALIZED CTE so the planner hashes it instead of choosing its own join shape against maintenance_leases.

func (*Queries) CountLiveConsumerSessions added in v0.3.0

func (q *Queries) CountLiveConsumerSessions(ctx context.Context, db DBTX) (*CountLiveConsumerSessionsRow, error)

Two fair-share denominators: every live instance can maintain topics with an explicit TTL, but only instances configured with a default expiration can even see default-TTL topics as candidates — dividing those by the total would leave most of a default-TTL backlog to the floor-of-1 trickle.

func (*Queries) DeleteExpiredConsumerSessions added in v0.3.0

func (q *Queries) DeleteExpiredConsumerSessions(ctx context.Context, db DBTX, cutoff pgtype.Timestamptz) error

GC for session rows left behind by dead instances (one per process lifetime, since instance ids are per-NewOutbox). Bounding the table keeps CountLiveConsumerSessions and the lease-liveness joins on a small seq scan. Deleting a row is equivalent to it being expired, so the cutoff buffer is caution, not correctness; a live instance wrongly swept just re-inserts itself on its next heartbeat.

func (*Queries) DeleteExpiredMessages added in v0.2.0

func (q *Queries) DeleteExpiredMessages(ctx context.Context, db DBTX, arg DeleteExpiredMessagesParams) error

func (*Queries) DeleteMessagesByIds

func (q *Queries) DeleteMessagesByIds(ctx context.Context, db DBTX, arg DeleteMessagesByIdsParams) error

func (*Queries) GetMaintenanceCandidateTopics added in v0.3.0

func (q *Queries) GetMaintenanceCandidateTopics(ctx context.Context, db DBTX, arg GetMaintenanceCandidateTopicsParams) ([]*GetMaintenanceCandidateTopicsRow, error)

Topics that may still hold unexpired messages (last insert newer than TTL + slack; NULL activity is treated as active, belt-and-braces for rows that predate the column), plus any topics force-included by the catch-up sweep, together with their maintenance-lease state. Lease liveness defers to the holder's consumer session, falling back to the staleness cutoff for pre-session holders (see SelectMaintenanceLeaseForUpdate). The plan is pinned to a deliberate shape: one seq scan of topics (the activity predicate is unindexable by design), maintenance_leases joined on its primary key, and consumer_sessions — the small side, kept small by the retention sweep — narrowed once into a MATERIALIZED CTE and hashed.

func (*Queries) GetOldestMessageInsertedAt added in v0.2.0

func (q *Queries) GetOldestMessageInsertedAt(ctx context.Context, db DBTX, topic string) (pgtype.Timestamptz, error)

func (*Queries) GetTopicForUpdate added in v0.2.0

func (q *Queries) GetTopicForUpdate(ctx context.Context, db DBTX, topic string) (*GetTopicForUpdateRow, error)

A NULL exclusive_consumer_expires_at on the topics row means "defer to the holder's consumer session for liveness"; a non-NULL value is a per-topic override (release, grace-period expiry, or a lease written by a pre-session version of pgoutbox) and wins the COALESCE. FOR UPDATE OF t locks only the topics row, not the joined session row shared by every topic the holder owns.

func (*Queries) GetTopicsWithExpiration added in v0.2.0

func (q *Queries) GetTopicsWithExpiration(ctx context.Context, db DBTX) ([]*GetTopicsWithExpirationRow, error)

func (*Queries) GetTopicsWithMessages added in v0.3.0

func (q *Queries) GetTopicsWithMessages(ctx context.Context, db DBTX) ([]string, error)

Loose index scan emulated over the (topic, id) PK: O(distinct topics) index probes the planner cannot degrade to a seq scan of messages. Used by the catch-up sweep to find topics holding messages regardless of activity.

func (*Queries) InsertMaintenanceLeaseIfAbsent added in v0.2.0

func (q *Queries) InsertMaintenanceLeaseIfAbsent(ctx context.Context, db DBTX, arg InsertMaintenanceLeaseIfAbsentParams) error

func (*Queries) InsertMaintenanceLeases added in v0.3.0

func (q *Queries) InsertMaintenanceLeases(ctx context.Context, db DBTX, arg InsertMaintenanceLeasesParams) ([]string, error)

Claim path for topics that have no lease row yet. RETURNING reports the subset this instance actually won; a concurrent instance may have inserted a row first, in which case the conflict arm drops that topic silently.

func (*Queries) InsertMessage

func (q *Queries) InsertMessage(ctx context.Context, db DBTX, arg []InsertMessageParams) (int64, error)

func (*Queries) InsertTopicIfAbsent added in v0.2.0

func (q *Queries) InsertTopicIfAbsent(ctx context.Context, db DBTX, arg InsertTopicIfAbsentParams) error

func (*Queries) ReleaseMaintenanceLease added in v0.3.0

func (q *Queries) ReleaseMaintenanceLease(ctx context.Context, db DBTX, arg ReleaseMaintenanceLeaseParams) error

Dormancy release: dormant topics carry no lease row at all. Guarded by holder so a lease that was concurrently taken over is never deleted.

func (*Queries) RenewTopicExclusiveConsumer added in v0.2.0

func (q *Queries) RenewTopicExclusiveConsumer(ctx context.Context, db DBTX, arg RenewTopicExclusiveConsumerParams) error

func (*Queries) SelectMaintenanceLeaseForUpdate added in v0.2.0

func (q *Queries) SelectMaintenanceLeaseForUpdate(ctx context.Context, db DBTX, arg SelectMaintenanceLeaseForUpdateParams) (*SelectMaintenanceLeaseForUpdateRow, error)

Lease liveness defers to the holder's consumer session; a holder with no session row (written by a pre-session version of pgoutbox) is judged by acquired_at against the caller-computed staleness cutoff, exactly the rule that version applies to itself. FOR UPDATE OF l leaves the session row unlocked, since every other lease held by the same instance reads it too.

func (*Queries) SetTopicExclusiveConsumer added in v0.2.0

func (q *Queries) SetTopicExclusiveConsumer(ctx context.Context, db DBTX, arg SetTopicExclusiveConsumerParams) error

func (*Queries) UpdateMaintenanceLease added in v0.2.0

func (q *Queries) UpdateMaintenanceLease(ctx context.Context, db DBTX, arg UpdateMaintenanceLeaseParams) error

func (*Queries) UpsertConsumerSession added in v0.3.0

func (q *Queries) UpsertConsumerSession(ctx context.Context, db DBTX, arg UpsertConsumerSessionParams) error

type ReleaseMaintenanceLeaseParams added in v0.3.0

type ReleaseMaintenanceLeaseParams struct {
	Topic    string    `json:"topic"`
	HolderID uuid.UUID `json:"holder_id"`
}

type RenewTopicExclusiveConsumerParams added in v0.2.0

type RenewTopicExclusiveConsumerParams struct {
	Topic                      string             `json:"topic"`
	ExclusiveConsumerID        *uuid.UUID         `json:"exclusive_consumer_id"`
	ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}

type SelectMaintenanceLeaseForUpdateParams added in v0.3.0

type SelectMaintenanceLeaseForUpdateParams struct {
	StaleCutoff pgtype.Timestamptz `json:"stale_cutoff"`
	Topic       string             `json:"topic"`
}

type SelectMaintenanceLeaseForUpdateRow added in v0.2.0

type SelectMaintenanceLeaseForUpdateRow struct {
	HolderID     uuid.UUID `json:"holder_id"`
	LeaseExpired bool      `json:"lease_expired"`
}

type SetTopicExclusiveConsumerParams added in v0.2.0

type SetTopicExclusiveConsumerParams struct {
	Topic                      string             `json:"topic"`
	ExclusiveConsumerID        *uuid.UUID         `json:"exclusive_consumer_id"`
	ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}

type Topic added in v0.2.0

type Topic struct {
	Topic                      string             `json:"topic"`
	ExpirationNanos            pgtype.Int8        `json:"expiration_nanos"`
	ExclusiveConsumerID        *uuid.UUID         `json:"exclusive_consumer_id"`
	ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
	LastInsertedAt             pgtype.Timestamptz `json:"last_inserted_at"`
}

type UpdateMaintenanceLeaseParams added in v0.2.0

type UpdateMaintenanceLeaseParams struct {
	Topic    string    `json:"topic"`
	HolderID uuid.UUID `json:"holder_id"`
}

type UpsertConsumerSessionParams added in v0.3.0

type UpsertConsumerSessionParams struct {
	ConsumerID                 uuid.UUID          `json:"consumer_id"`
	ExpiresAt                  pgtype.Timestamptz `json:"expires_at"`
	MaintainsDefaultExpiration bool               `json:"maintains_default_expiration"`
}

Jump to

Keyboard shortcuts

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