sqlcgen

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiToken

type ApiToken struct {
	ID          uuid.UUID
	TokenHash   string
	Role        string
	ProjectIds  []uuid.UUID
	Description pgtype.Text
	CreatedAt   pgtype.Timestamptz
	RevokedAt   pgtype.Timestamptz
}

type AuditLog

type AuditLog struct {
	ID         int64
	At         pgtype.Timestamptz
	Actor      string
	Action     string
	ObjectType pgtype.Text
	ObjectID   pgtype.Text
	Details    []byte
}

type CountEventsParams

type CountEventsParams struct {
	Cloud        string
	ResourceType string
	ResourceID   string
	EventType    string
	FromTs       pgtype.Timestamptz
	ToTs         pgtype.Timestamptz
}

type CurrentResource

type CurrentResource struct {
	Cloud         string
	Platform      string
	ResourceType  string
	ResourceID    string
	ProjectID     string
	State         string
	Size          []byte
	CreatedAt     pgtype.Timestamptz
	DeletedAt     pgtype.Timestamptz
	LastEventType string
	LastEventAt   pgtype.Timestamptz
	LastPayload   []byte
	FirstEventAt  pgtype.Timestamptz
}

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
}

type Event

type Event struct {
	EventID      string
	Timestamp    pgtype.Timestamptz
	ReceivedAt   pgtype.Timestamptz
	EventType    string
	Platform     string
	Cloud        string
	ResourceType string
	ResourceID   string
	ProjectID    string
	Source       string
	Payload      []byte
}

type IngestCredential

type IngestCredential struct {
	ID          uuid.UUID
	Platform    string
	Cloud       string
	TokenHash   string
	Description pgtype.Text
	CreatedAt   pgtype.Timestamptz
	RevokedAt   pgtype.Timestamptz
}

type ListCandidatesParams

type ListCandidatesParams struct {
	Clouds     []string
	PeriodFrom pgtype.Timestamptz
	PeriodTo   pgtype.Timestamptz
}

type ListCandidatesRow

type ListCandidatesRow struct {
	Cloud        string
	Platform     string
	ResourceType string
	ResourceID   string
}

type ListHistoryParams

type ListHistoryParams struct {
	Cloud        string
	ResourceType string
	ResourceID   string
	PeriodTo     pgtype.Timestamptz
}

type ListLateEventsParams

type ListLateEventsParams struct {
	MaxResources int64
	PeriodFrom   pgtype.Timestamptz
	PeriodTo     pgtype.Timestamptz
	Since        pgtype.Timestamptz
}

type ListLateEventsRow

type ListLateEventsRow struct {
	Cloud          string
	Platform       string
	ResourceType   string
	ResourceID     string
	Events         int64
	LastReceivedAt pgtype.Timestamptz
	Resources      int64
}

type ListProjectsRow

type ListProjectsRow struct {
	ID         uuid.UUID
	Platform   string
	Cloud      string
	ExternalID string
}

type ListRelationsOverlappingParams

type ListRelationsOverlappingParams struct {
	RelationTypes []string
	PeriodTo      pgtype.Timestamptz
	PeriodFrom    pgtype.Timestamptz
}

type ListRelationsOverlappingRow

type ListRelationsOverlappingRow struct {
	ID           uuid.UUID
	SourceID     uuid.UUID
	TargetID     uuid.UUID
	RelationType string
	Metadata     []byte
	ValidFrom    pgtype.Timestamptz
	ValidTo      pgtype.Timestamptz
}

type Project

type Project struct {
	ID         uuid.UUID
	Platform   string
	Cloud      string
	ExternalID string
	Name       pgtype.Text
	Metadata   []byte
	CreatedAt  pgtype.Timestamptz
}

type ProjectRelation

type ProjectRelation struct {
	ID           uuid.UUID
	SourceID     uuid.UUID
	TargetID     uuid.UUID
	RelationType string
	Metadata     []byte
	ValidFrom    pgtype.Timestamptz
	ValidTo      pgtype.Timestamptz
	CreatedAt    pgtype.Timestamptz
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CountEvents

func (q *Queries) CountEvents(ctx context.Context, arg CountEventsParams) (int64, error)

The events of one type a counter measures inside one usage interval. The interval is half-open, [from_ts, to_ts), the same bound the interval itself has, and the key carries the cloud and the resource type beside the id because an id is unique only within both. idx_events_resource serves the predicate on uncompressed chunks; a chunk past the 90-day compression policy is segmented by (cloud, resource_type) alone, so the resource id and the event type are filtered after decompression, which is what a correction of an older period pays.

func (*Queries) ListCandidates

func (q *Queries) ListCandidates(ctx context.Context, arg ListCandidatesParams) ([]ListCandidatesRow, error)

The resources a period can bill. The projection is the index: its rows are never deleted, so a resource that lived during the period is still there to be found, whatever happened to it since. A NULL cloud list means every cloud.

func (*Queries) ListHistory

func (q *Queries) ListHistory(ctx context.Context, arg ListHistoryParams) ([]Event, error)

The full history of one candidate up to the period end. The fold starts at the first event there is, because the state the resource holds at the period start is whatever the events before it left behind.

func (*Queries) ListLateEvents

func (q *Queries) ListLateEvents(ctx context.Context, arg ListLateEventsParams) ([]ListLateEventsRow, error)

The late events of one billing period, the detection of WP 3.9 (roadmap/03-phase-3-metering-rating.md, under "Late-event detection"): the events dated inside the period that were received strictly after the instant the caller passes, the runs.stats.snapshot_at of the finalized run, grouped per resource. The range over timestamp is answered by chunk exclusion, and the lower bound on received_at by idx_events_received (reporting migration 0009) on the uncompressed chunks; a chunk past the 90-day compression policy is segmented by (cloud, resource_type) and ordered by nothing, so its batches carry no bounds on received_at and are filtered after decompression, which is what detecting the late events of an older period pays.

The groups are bounded by max_resources. A period finalized before its ingest had settled has one group per resource of the fleet, and what a caller does with the groups is print one line each. The groups the limit cuts off are counted all the same: resources is how many arrived late whatever the limit let through, and every row carries it, so a caller that read one row knows how many it did not.

The strict comparison leaves one window open, and the issue holds it as a Non-Goal: an ingest transaction that began before the snapshot and committed after it carries a received_at below snapshot_at, so its events are not listed here although a correction of the period re-meters them. Ingest transactions are milliseconds long, and the window is recorded here rather than papered over with a margin.

func (*Queries) ListProjects

func (q *Queries) ListProjects(ctx context.Context) ([]ListProjectsRow, error)

The project registry, read whole: attribution walks the graph over these UUIDs, and the resources it walks from carry the external id rather than the registry's.

func (*Queries) ListRelationsOverlapping

func (q *Queries) ListRelationsOverlapping(ctx context.Context, arg ListRelationsOverlappingParams) ([]ListRelationsOverlappingRow, error)

The relations that apply to a period, which are the ones whose validity overlaps it (D4). A relation closed inside the period still carries the cost the period produced before it closed; v1 does not prorate a relation within a period.

func (*Queries) SnapshotTime

func (q *Queries) SnapshotTime(ctx context.Context) (pgtype.Timestamptz, error)

The first statement of the REPEATABLE READ transaction a run opens. Reading now() takes the snapshot every later query in that transaction sees, and the value it returns is that snapshot's time, which the run records in runs.stats.snapshot_at.

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type RejectedEvent

type RejectedEvent struct {
	ID         uuid.UUID
	ReceivedAt pgtype.Timestamptz
	Reason     string
	Raw        []byte
}

type ResourceType

type ResourceType struct {
	Platform     string
	ResourceType string
	SizeSchema   []byte
	UpdatedAt    pgtype.Timestamptz
}

type SizeName added in v0.5.0

type SizeName struct {
	Cloud        string
	ResourceType string
	Member       string
	Value        string
	Name         string
}

type SyncRun

type SyncRun struct {
	ID          uuid.UUID
	Cloud       string
	StartedAt   pgtype.Timestamptz
	CompletedAt pgtype.Timestamptz
	Status      string
	Stats       []byte
}

Jump to

Keyboard shortcuts

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