Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlc

package
v3.51.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	ID         int64
	Owner      string
	Course     string
	Assignment string
	Op         string
	Params     []byte
	Status     string
	Detail     string
	At         time.Time
}

type ActivityForParams

type ActivityForParams struct {
	Owner      string
	Course     string
	Assignment string
	Lim        *int32
}

type AllActivityForParams

type AllActivityForParams struct {
	Owner string
	Lim   *int32
}

type CancelJobParams

type CancelJobParams struct {
	ID         string
	Owner      string
	FinishedAt time.Time
}

type ClaimDueJobParams

type ClaimDueJobParams struct {
	Now      time.Time
	WorkerID string
}

type Course

type Course struct {
	Owner         string
	Name          string
	Source        []byte
	FormatVersion int
	RawYaml       []byte
	ImportedAt    time.Time
	UpdatedAt     time.Time
}

type CourseActivityForParams

type CourseActivityForParams struct {
	Owner  string
	Course string
	Lim    *int32
}

type CourseOfParams

type CourseOfParams struct {
	Owner string
	Name  string
}

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 DeleteCourseParams

type DeleteCourseParams struct {
	Owner string
	Name  string
}

type Event

type Event struct {
	ID         int64
	At         time.Time
	Type       string
	Severity   string
	Actor      string
	ActorName  string
	Department string
	Course     string
	Assignment string
	Op         string
	Detail     string
	JobID      string
}

type EventsBetweenParams

type EventsBetweenParams struct {
	At   time.Time
	At_2 time.Time
}

type FinishJobParams

type FinishJobParams struct {
	ID         string
	Status     string
	Log        string
	Err        string
	FinishedAt time.Time
}

type InsertAccessRequestParams added in v3.48.0

type InsertAccessRequestParams struct {
	Email       string
	Name        string
	Department  string
	Reason      string
	RequestedAt time.Time
}

type JobOfParams

type JobOfParams struct {
	ID    string
	Owner string
}

type JobsOfParams

type JobsOfParams struct {
	Owner    string
	Statuses []string
}

type Querier

type Querier interface {
	// The three reads below all take a nullable limit, because `limit null` means
	// "no limit" in PostgreSQL -- exactly the `limit <= 0` case of the findActivity
	// helper they replace. The GUI reads pass the cap; the audit dump passes null.
	ActivityFor(ctx context.Context, arg ActivityForParams) ([]Activity, error)
	AllActivityFor(ctx context.Context, arg AllActivityForParams) ([]Activity, error)
	// Only one's own, only while still pending. A job already running is too late
	// and another owner's job is invisible: both return no row, and the caller turns
	// that into the same error. That sameness is deliberate -- "not found" must not
	// become an oracle for whether someone else has a job with that id.
	CancelJob(ctx context.Context, arg CancelJobParams) (ScheduledJob, error)
	// The atomic claim. This single statement is what replaces a distributed lock:
	// exactly one runner ever owns a given job.
	//
	// FOR UPDATE SKIP LOCKED is strictly stronger than the FindOneAndUpdate it
	// replaces -- several runners do not queue behind each other, they take
	// different jobs.
	//
	// Deliberately NOT wrapped in an explicit transaction. The row lock ends with
	// the statement, and the flip to 'running' IS the lock. Holding a transaction
	// open across the job's execution would mean minutes with a locked row and a
	// pool connection tied up, which is the obvious-looking mistake here.
	ClaimDueJob(ctx context.Context, arg ClaimDueJobParams) (ScheduledJob, error)
	CourseActivityFor(ctx context.Context, arg CourseActivityForParams) ([]Activity, error)
	CourseOf(ctx context.Context, arg CourseOfParams) (Course, error)
	// Every read here takes an owner and filters on it. There is deliberately no
	// query that reads a course by name alone: owner isolation is enforced by the
	// shape of this file, not by remembering to add a filter at each call site.
	CoursesOf(ctx context.Context, owner string) ([]Course, error)
	// :execrows so the caller can tell "deleted" from "there was nothing to
	// delete". Deleting another user's course must report not-found rather than
	// pretending it worked.
	DeleteCourse(ctx context.Context, arg DeleteCourseParams) (int64, error)
	DeleteUser(ctx context.Context, email string) (int64, error)
	// An update to null, not a delete of the row: the row is the anchor for the
	// other per-user secrets this table is meant to grow, and removing a GitLab
	// token must not take them with it. Exactly the $unset semantics.
	//
	// A row that does not exist matches nothing and reports success, as before: the
	// caller's intent is "make sure there is none".
	DeleteUserGitLabToken(ctx context.Context, owner string) error
	// [since, until) -- half open on purpose. The upper bound belongs to the NEXT
	// digest window; including it would mail the same event twice.
	//
	// Oldest first, with the id as tiebreaker. Mongo left events sharing a timestamp
	// in an arbitrary order; this is a stable total order and a free improvement.
	EventsBetween(ctx context.Context, arg EventsBetweenParams) ([]Event, error)
	// Matching nothing is success, as before: the runner logs an error here, and a
	// job the retention sweep has already removed should not produce noise.
	FinishJob(ctx context.Context, arg FinishJobParams) error
	GetUser(ctx context.Context, email string) (User, error)
	GetUserSecret(ctx context.Context, owner string) (UserSecret, error)
	// `do nothing` on a conflict, so a double click or a second tab cannot turn one
	// request into two admin mails: only the insert that actually created the row
	// gets a row back, the other gets pgx.ErrNoRows.
	InsertAccessRequest(ctx context.Context, arg InsertAccessRequestParams) (User, error)
	JobOf(ctx context.Context, arg JobOfParams) (ScheduledJob, error)
	// The status list is optional: empty or null means no filter, which is what the
	// GUI's unfiltered view passes. Spelled with cardinality rather than a second
	// query so there is one ordering to keep correct.
	JobsOf(ctx context.Context, arg JobsOfParams) ([]ScheduledJob, error)
	// Open requests first (they are what an admin comes here for), then everyone
	// else; newest request first within each group.
	ListUsers(ctx context.Context) ([]User, error)
	MarkNotified(ctx context.Context, id string) error
	// The replacement for Mongo's TTL index on at: the monitoring trail is a rolling
	// window, not a permanent archive.
	ReapExpiredEvents(ctx context.Context, before time.Time) (int64, error)
	// The replacement for Mongo's TTL index on finished_at. `finished_at is null`
	// falls out of the comparison on its own, so pending and running jobs are never
	// reaped -- exactly what the partial TTL index did.
	ReapExpiredJobs(ctx context.Context, before time.Time) (int64, error)
	// The admin page's live feed. A null limit means unlimited, as with activity.
	RecentEvents(ctx context.Context, arg RecentEventsParams) ([]Event, error)
	RecordActivity(ctx context.Context, arg RecordActivityParams) error
	RecordEvent(ctx context.Context, arg RecordEventParams) error
	// An upsert on the key, replacing the whole row -- what ReplaceOne(upsert) did.
	// imported_at is included on purpose: the caller carries it on the struct and a
	// replace has to write it back, or editing a course would reset when it was
	// imported.
	SaveCourse(ctx context.Context, arg SaveCourseParams) error
	SaveJob(ctx context.Context, arg SaveJobParams) error
	// The column list is what makes this touch only the gitlab fields: other
	// secrets on the row survive. In Mongo that was a $set of three named keys and
	// depended on remembering to name them.
	SaveUserGitLabToken(ctx context.Context, arg SaveUserGitLabTokenParams) error
	// Self-healing: the row is seeded by the migration, but an upsert means a
	// vanished row does not turn the nightly digest into a permanent failure.
	SetSummarySentAt(ctx context.Context, summarySentAt *time.Time) error
	SetUserStatus(ctx context.Context, arg SetUserStatusParams) (User, error)
	SystemState(ctx context.Context) (SystemState, error)
	// The runner's notify sweep, across all owners: one mail per finished job.
	// Cancelled is excluded -- the user did that on purpose and there is no mail for
	// it. This is what makes "mail on every terminal state" survive a crash between
	// finishing a job and mailing it.
	UnnotifiedTerminalJobs(ctx context.Context) ([]ScheduledJob, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) ActivityFor

func (q *Queries) ActivityFor(ctx context.Context, arg ActivityForParams) ([]Activity, error)

The three reads below all take a nullable limit, because `limit null` means "no limit" in PostgreSQL -- exactly the `limit <= 0` case of the findActivity helper they replace. The GUI reads pass the cap; the audit dump passes null.

func (*Queries) AllActivityFor

func (q *Queries) AllActivityFor(ctx context.Context, arg AllActivityForParams) ([]Activity, error)

func (*Queries) CancelJob

func (q *Queries) CancelJob(ctx context.Context, arg CancelJobParams) (ScheduledJob, error)

Only one's own, only while still pending. A job already running is too late and another owner's job is invisible: both return no row, and the caller turns that into the same error. That sameness is deliberate -- "not found" must not become an oracle for whether someone else has a job with that id.

func (*Queries) ClaimDueJob

func (q *Queries) ClaimDueJob(ctx context.Context, arg ClaimDueJobParams) (ScheduledJob, error)

The atomic claim. This single statement is what replaces a distributed lock: exactly one runner ever owns a given job.

FOR UPDATE SKIP LOCKED is strictly stronger than the FindOneAndUpdate it replaces -- several runners do not queue behind each other, they take different jobs.

Deliberately NOT wrapped in an explicit transaction. The row lock ends with the statement, and the flip to 'running' IS the lock. Holding a transaction open across the job's execution would mean minutes with a locked row and a pool connection tied up, which is the obvious-looking mistake here.

func (*Queries) CourseActivityFor

func (q *Queries) CourseActivityFor(ctx context.Context, arg CourseActivityForParams) ([]Activity, error)

func (*Queries) CourseOf

func (q *Queries) CourseOf(ctx context.Context, arg CourseOfParams) (Course, error)

func (*Queries) CoursesOf

func (q *Queries) CoursesOf(ctx context.Context, owner string) ([]Course, error)

Every read here takes an owner and filters on it. There is deliberately no query that reads a course by name alone: owner isolation is enforced by the shape of this file, not by remembering to add a filter at each call site.

func (*Queries) DeleteCourse

func (q *Queries) DeleteCourse(ctx context.Context, arg DeleteCourseParams) (int64, error)

:execrows so the caller can tell "deleted" from "there was nothing to delete". Deleting another user's course must report not-found rather than pretending it worked.

func (*Queries) DeleteUser added in v3.48.0

func (q *Queries) DeleteUser(ctx context.Context, email string) (int64, error)

func (*Queries) DeleteUserGitLabToken

func (q *Queries) DeleteUserGitLabToken(ctx context.Context, owner string) error

An update to null, not a delete of the row: the row is the anchor for the other per-user secrets this table is meant to grow, and removing a GitLab token must not take them with it. Exactly the $unset semantics.

A row that does not exist matches nothing and reports success, as before: the caller's intent is "make sure there is none".

func (*Queries) EventsBetween

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

[since, until) -- half open on purpose. The upper bound belongs to the NEXT digest window; including it would mail the same event twice.

Oldest first, with the id as tiebreaker. Mongo left events sharing a timestamp in an arbitrary order; this is a stable total order and a free improvement.

func (*Queries) FinishJob

func (q *Queries) FinishJob(ctx context.Context, arg FinishJobParams) error

Matching nothing is success, as before: the runner logs an error here, and a job the retention sweep has already removed should not produce noise.

func (*Queries) GetUser added in v3.48.0

func (q *Queries) GetUser(ctx context.Context, email string) (User, error)

func (*Queries) GetUserSecret

func (q *Queries) GetUserSecret(ctx context.Context, owner string) (UserSecret, error)

func (*Queries) InsertAccessRequest added in v3.48.0

func (q *Queries) InsertAccessRequest(ctx context.Context, arg InsertAccessRequestParams) (User, error)

`do nothing` on a conflict, so a double click or a second tab cannot turn one request into two admin mails: only the insert that actually created the row gets a row back, the other gets pgx.ErrNoRows.

func (*Queries) JobOf

func (q *Queries) JobOf(ctx context.Context, arg JobOfParams) (ScheduledJob, error)

func (*Queries) JobsOf

func (q *Queries) JobsOf(ctx context.Context, arg JobsOfParams) ([]ScheduledJob, error)

The status list is optional: empty or null means no filter, which is what the GUI's unfiltered view passes. Spelled with cardinality rather than a second query so there is one ordering to keep correct.

func (*Queries) ListUsers added in v3.48.0

func (q *Queries) ListUsers(ctx context.Context) ([]User, error)

Open requests first (they are what an admin comes here for), then everyone else; newest request first within each group.

func (*Queries) MarkNotified

func (q *Queries) MarkNotified(ctx context.Context, id string) error

func (*Queries) ReapExpiredEvents

func (q *Queries) ReapExpiredEvents(ctx context.Context, before time.Time) (int64, error)

The replacement for Mongo's TTL index on at: the monitoring trail is a rolling window, not a permanent archive.

func (*Queries) ReapExpiredJobs

func (q *Queries) ReapExpiredJobs(ctx context.Context, before time.Time) (int64, error)

The replacement for Mongo's TTL index on finished_at. `finished_at is null` falls out of the comparison on its own, so pending and running jobs are never reaped -- exactly what the partial TTL index did.

func (*Queries) RecentEvents

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

The admin page's live feed. A null limit means unlimited, as with activity.

func (*Queries) RecordActivity

func (q *Queries) RecordActivity(ctx context.Context, arg RecordActivityParams) error

func (*Queries) RecordEvent

func (q *Queries) RecordEvent(ctx context.Context, arg RecordEventParams) error

func (*Queries) SaveCourse

func (q *Queries) SaveCourse(ctx context.Context, arg SaveCourseParams) error

An upsert on the key, replacing the whole row -- what ReplaceOne(upsert) did. imported_at is included on purpose: the caller carries it on the struct and a replace has to write it back, or editing a course would reset when it was imported.

func (*Queries) SaveJob

func (q *Queries) SaveJob(ctx context.Context, arg SaveJobParams) error

func (*Queries) SaveUserGitLabToken

func (q *Queries) SaveUserGitLabToken(ctx context.Context, arg SaveUserGitLabTokenParams) error

The column list is what makes this touch only the gitlab fields: other secrets on the row survive. In Mongo that was a $set of three named keys and depended on remembering to name them.

func (*Queries) SetSummarySentAt

func (q *Queries) SetSummarySentAt(ctx context.Context, summarySentAt *time.Time) error

Self-healing: the row is seeded by the migration, but an upsert means a vanished row does not turn the nightly digest into a permanent failure.

func (*Queries) SetUserStatus added in v3.48.0

func (q *Queries) SetUserStatus(ctx context.Context, arg SetUserStatusParams) (User, error)

func (*Queries) SystemState

func (q *Queries) SystemState(ctx context.Context) (SystemState, error)

func (*Queries) UnnotifiedTerminalJobs

func (q *Queries) UnnotifiedTerminalJobs(ctx context.Context) ([]ScheduledJob, error)

The runner's notify sweep, across all owners: one mail per finished job. Cancelled is excluded -- the user did that on purpose and there is no mail for it. This is what makes "mail on every terminal state" survive a crash between finishing a job and mailing it.

func (*Queries) WithTx

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

type RecentEventsParams

type RecentEventsParams struct {
	At  time.Time
	Lim *int32
}

type RecordActivityParams

type RecordActivityParams struct {
	Owner      string
	Course     string
	Assignment string
	Op         string
	Params     []byte
	Status     string
	Detail     string
	At         time.Time
}

type RecordEventParams

type RecordEventParams struct {
	At         time.Time
	Type       string
	Severity   string
	Actor      string
	ActorName  string
	Department string
	Course     string
	Assignment string
	Op         string
	Detail     string
	JobID      string
}

type SaveCourseParams

type SaveCourseParams struct {
	Owner      string
	Name       string
	Source     []byte
	RawYaml    []byte
	ImportedAt time.Time
	UpdatedAt  time.Time
}

type SaveJobParams

type SaveJobParams struct {
	ID           string
	Owner        string
	Op           string
	Course       string
	Assignment   string
	OnlyFor      []string
	Params       []byte
	RunAt        time.Time
	ConfigHash   string
	Status       string
	GraceMinutes int
	CreatedAt    time.Time
	StartedAt    *time.Time
	FinishedAt   *time.Time
	Log          string
	Err          string
	Notified     bool
	WorkerID     string
}

type SaveUserGitLabTokenParams

type SaveUserGitLabTokenParams struct {
	Owner            string
	GitlabKeyVersion *int
	GitlabNonce      []byte
	GitlabCiphertext []byte
	GitlabUpdatedAt  *time.Time
}

type ScheduledJob

type ScheduledJob struct {
	ID           string
	Owner        string
	Op           string
	Course       string
	Assignment   string
	OnlyFor      []string
	Params       []byte
	RunAt        time.Time
	ConfigHash   string
	Status       string
	GraceMinutes int
	CreatedAt    time.Time
	StartedAt    *time.Time
	FinishedAt   *time.Time
	Log          string
	Err          string
	Notified     bool
	WorkerID     string
}

type SetUserStatusParams added in v3.48.0

type SetUserStatusParams struct {
	Email     string
	Status    string
	DecidedAt *time.Time
	DecidedBy string
}

type SystemState

type SystemState struct {
	ID            string
	SummarySentAt *time.Time
}

type User added in v3.48.0

type User struct {
	Email       string
	Name        string
	Department  string
	Status      string
	Reason      string
	RequestedAt time.Time
	DecidedAt   *time.Time
	DecidedBy   string
}

type UserSecret

type UserSecret struct {
	Owner            string
	GitlabKeyVersion *int
	GitlabNonce      []byte
	GitlabCiphertext []byte
	GitlabUpdatedAt  *time.Time
}

Jump to

Keyboard shortcuts

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