postgres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0, MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres is a server.Store on PostgreSQL, through pgx v5. Its tables are in a schema of their own, and New raises them to the version the code knows.

Index

Constants

View Source
const ReachWithin = 10 * time.Second

ReachWithin is how long New waits to reach the database (less when its context ends sooner): a server that cannot reach it stops, saying so, before it takes requests.

Variables

This section is empty.

Functions

func Version

func Version() int

Version answers the version of the tables this code knows.

Types

type Store

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

Store is a store on PostgreSQL.

func New

func New(ctx context.Context, pool *pgxpool.Pool, schema string) (*Store, error)

New makes a store in the schema (requests when ""), raising its tables to the version the code knows. It first reaches the database, waiting at most ReachWithin, and says so when it cannot. Two processes that start at once raise the tables once; a process whose code knows an older version than the tables' refuses to start.

func (*Store) Begin

func (s *Store) Begin(ctx context.Context, b server.Begun) (server.Begun, error)

Begin keeps an operation the first time its key is given, and answers what is kept. A key whose record went between the two statements (its reply was kept) answers b: the save that follows finds the reply. b is answered as it is kept, its time cut to the microsecond (as the driver cuts it) and in UTC.

func (*Store) BundleArchive

func (s *Store) BundleArchive(ctx context.Context, digest string) ([]byte, error)

BundleArchive reads a bundle's archive, or ErrNotFound.

func (*Store) Bundles

func (s *Store) Bundles(ctx context.Context) ([]server.Bundle, error)

Bundles reads every bundle the store keeps, without their archives, in the order they were uploaded.

func (*Store) CountMine

func (s *Store) CountMine(ctx context.Context, person string) (map[string]server.MineCount, error)

CountMine counts a person's own tickets, by kind and by state.

func (*Store) CountTickets

func (s *Store) CountTickets(ctx context.Context, versions []server.KindVersion) ([]server.TicketCount, error)

CountTickets counts the tickets of the versions given by kind, version and status.

func (*Store) CountWaiting

func (s *Store) CountWaiting(ctx context.Context, person string) (map[string]int, error)

CountWaiting counts the tickets that wait for the person, by kind.

func (*Store) DoneToDo

func (s *Store) DoneToDo(ctx context.Context, id string, at time.Time) error

DoneToDo marks one done.

func (*Store) Draft

func (s *Store) Draft(ctx context.Context, person, id string) (server.Draft, error)

Draft reads a person's draft.

func (*Store) DueTimers

func (s *Store) DueTimers(ctx context.Context, now time.Time, lease time.Duration, limit int) ([]server.Timer, error)

DueTimers leases the timers that are due.

func (*Store) DueToDo

func (s *Store) DueToDo(ctx context.Context, now time.Time, lease time.Duration, limit int) ([]server.ToDo, error)

DueToDo leases the things to do that are due.

func (*Store) Empty

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

Empty deletes everything the store keeps. For tests.

func (*Store) Files

func (s *Store) Files() server.Files

Files answers the store's attachments: a server.Files in the table files of the store's schema, each file's bytes in a bytea column. A file is read into memory whole, so keep the largest attachment the server takes (web.Config.MaxFile) to a size memory holds many of at once.

func (*Store) ForgetDrafts

func (s *Store) ForgetDrafts(ctx context.Context, before time.Time, limit int) (int, error)

ForgetDrafts forgets up to limit drafts kept before `before`, the oldest first.

func (*Store) ForgetOperations

func (s *Store) ForgetOperations(ctx context.Context, before time.Time, limit int) (int, error)

ForgetOperations forgets up to limit operations answered before `before` and up to limit operations begun before it whose reply was never kept, the oldest first of each, and answers how many of both. Of one time, it forgets them by person, then by key, as Go compares strings (collate "C"), whatever the database's collation (Store.ForgetOperations).

func (*Store) Imports

func (s *Store) Imports(ctx context.Context, since time.Time) ([]time.Time, error)

Imports answers the times of the imports that added a snapshot at or after since.

func (*Store) KeepDraft

func (s *Store) KeepDraft(ctx context.Context, d server.Draft, max int) error

KeepDraft keeps a draft, forgetting the person's oldest past max.

func (*Store) KeepOutcome

func (s *Store) KeepOutcome(ctx context.Context, id string, at time.Time, outcome json.RawMessage) error

KeepOutcome keeps what the work of one said became of it, in place of what it said before.

func (*Store) KeepToDo

func (s *Store) KeepToDo(ctx context.Context, td server.ToDo) error

KeepToDo keeps a thing to do that no move holds; one with the same ID is left as it is.

func (*Store) KeepUpload

func (s *Store) KeepUpload(ctx context.Context, u server.Upload, max int) (string, error)

KeepUpload records an upload, unless the person has one with its key, or max uploads no ticket holds. The uploads of one person are recorded one at a time, under a lock of the person's, so that two at once are counted, and looked for by their key, one after the other.

func (*Store) KeptVersions

func (s *Store) KeptVersions(ctx context.Context) ([]server.TicketCount, error)

KeptVersions counts the tickets of every version the store keeps any of, by kind, version and status.

func (*Store) LastImport

func (s *Store) LastImport(ctx context.Context) (server.Record, error)

LastImport reads the latest record of an import from the source.

func (*Store) LatestOrganization

func (s *Store) LatestOrganization(ctx context.Context) (server.OrgSnapshot, error)

LatestOrganization reads the latest snapshot.

func (*Store) LetGoUploads

func (s *Store) LetGoUploads(ctx context.Context, before time.Time, limit int) ([]server.Upload, error)

LetGoUploads answers the uploads let go whose files are not deleted yet, then lets go of the oldest uploads made before `before` that no ticket holds, skipping the ones a save is holding.

func (*Store) Lock

func (s *Store) Lock(ctx context.Context, ticket string) (context.Context, func(), error)

Lock takes a ticket's lock: a PostgreSQL advisory lock, held on a connection of its own, which the answered context carries for the ticket's reads and save. It waits without holding a connection.

func (*Store) Mine

func (s *Store) Mine(ctx context.Context, person string, q server.MineQuery) ([]server.TicketRecord, error)

Mine reads a person's own tickets, the newest first.

func (*Store) Moves

func (s *Store) Moves(ctx context.Context, ticket string) ([]server.MoveRecord, error)

Moves reads a ticket's moves.

func (*Store) OpenUploads

func (s *Store) OpenUploads(ctx context.Context, person string) (int, error)

OpenUploads counts a person's uploads that no ticket holds and that are not let go.

func (*Store) Operation

func (s *Store) Operation(ctx context.Context, person, key string) (server.OperationRecord, error)

Operation reads what was answered to a key.

func (*Store) Organization

func (s *Store) Organization(ctx context.Context, id string) (server.OrgSnapshot, error)

Organization reads a snapshot.

func (*Store) PutOffTimer

func (s *Store) PutOffTimer(ctx context.Context, k server.TimerKey, try time.Time) error

PutOffTimer keeps a timer to be tried again later.

func (*Store) Record

func (s *Store) Record(ctx context.Context, id string) (server.Record, error)

Record reads a record by its ID.

func (*Store) Records

func (s *Store) Records(ctx context.Context, q server.RecordQuery) ([]server.Line, error)

Records reads a page of the record, the newest first.

func (*Store) Renew

func (s *Store) Renew(ctx context.Context, b server.Begun) error

Renew keeps b in place of what was kept for its key.

func (*Store) RetryToDo

func (s *Store) RetryToDo(ctx context.Context, id string, try time.Time, why string) error

RetryToDo gives one up to be tried again.

func (*Store) Revoke

func (s *Store) Revoke(ctx context.Context, session string, until time.Time) error

Revoke records that a session of signing in was ended before its time (a sign-out): every process that reads the same tables refuses the session from then on. until is when the session would have ended anyway; the records whose time has passed are dropped as others are recorded. With Revoked, the store is what a way of signing in asks about ended sessions (the Revocations of package oidc).

func (*Store) Revoked

func (s *Store) Revoked(ctx context.Context, session string) (bool, error)

Revoked reports whether a session was recorded as ended.

func (*Store) Save

func (s *Store) Save(ctx context.Context, m *server.Move) error

Save writes a move, all or nothing.

func (*Store) SaveChange

func (s *Store) SaveChange(ctx context.Context, c *server.Change) error

SaveChange writes a change an administrator made, all or nothing (server.Change).

func (*Store) SaveOrganization

func (s *Store) SaveOrganization(ctx context.Context, o server.OrgSnapshot) error

SaveOrganization keeps a snapshot and makes it the latest, under the lock every making of a latest takes (orgLock).

func (*Store) Starts

func (s *Store) Starts(ctx context.Context) ([]server.Start, error)

Starts reads the start of each version an administrator decided.

func (*Store) Ticket

func (s *Store) Ticket(ctx context.Context, id string) (server.TicketRecord, error)

Ticket reads a ticket.

func (*Store) Tickets

func (s *Store) Tickets(ctx context.Context, q server.TicketsQuery) ([]server.TicketRecord, error)

Tickets reads the tickets of some versions of a kind, the newest first.

func (*Store) Timers

func (s *Store) Timers(ctx context.Context, ticket string) ([]server.Timer, error)

Timers reads a ticket's timers.

func (*Store) ToDoItem

func (s *Store) ToDoItem(ctx context.Context, id string) (server.ToDo, error)

ToDoItem reads one thing to do.

func (*Store) ToDoList

func (s *Store) ToDoList(ctx context.Context, ticket string) ([]server.ToDo, error)

ToDoList reads a ticket's things to do.

func (*Store) Trial

func (s *Store) Trial(ctx context.Context) (any, func(), error)

Trial begins a transaction that end rolls back.

func (*Store) UploadOf

func (s *Store) UploadOf(ctx context.Context, person, key string) (string, error)

UploadOf answers the upload a person made with a key that is not let go.

func (*Store) UploadsDeleted

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

UploadsDeleted records that the files of uploads let go are deleted.

func (*Store) Waiting

func (s *Store) Waiting(ctx context.Context, people []string, q server.WaitingQuery) ([]server.TicketRecord, error)

Waiting reads the tickets that wait for any of the people, the newest first.

type Tx

type Tx struct {
	pgx.Tx
	// contains filtered or unexported fields
}

Tx is what a move's Books is given: the move's transaction, a pgx.Tx (books in the same database write in it, and what they write is kept only with the move), with AfterCommit for what books keep outside the database.

func (*Tx) AfterCommit

func (t *Tx) AfterCommit(f func())

AfterCommit registers f to be done once the move is saved; never, in a trial's transaction.

Jump to

Keyboard shortcuts

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