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
- func Version() int
- type Store
- func (s *Store) Begin(ctx context.Context, b server.Begun) (server.Begun, error)
- func (s *Store) BundleArchive(ctx context.Context, digest string) ([]byte, error)
- func (s *Store) Bundles(ctx context.Context) ([]server.Bundle, error)
- func (s *Store) CountMine(ctx context.Context, person string) (map[string]server.MineCount, error)
- func (s *Store) CountTickets(ctx context.Context, versions []server.KindVersion) ([]server.TicketCount, error)
- func (s *Store) CountWaiting(ctx context.Context, person string) (map[string]int, error)
- func (s *Store) DoneToDo(ctx context.Context, id string, at time.Time) error
- func (s *Store) Draft(ctx context.Context, person, id string) (server.Draft, error)
- func (s *Store) DueTimers(ctx context.Context, now time.Time, lease time.Duration, limit int) ([]server.Timer, error)
- func (s *Store) DueToDo(ctx context.Context, now time.Time, lease time.Duration, limit int) ([]server.ToDo, error)
- func (s *Store) Empty(ctx context.Context) error
- func (s *Store) Files() server.Files
- func (s *Store) ForgetDrafts(ctx context.Context, before time.Time, limit int) (int, error)
- func (s *Store) ForgetOperations(ctx context.Context, before time.Time, limit int) (int, error)
- func (s *Store) Imports(ctx context.Context, since time.Time) ([]time.Time, error)
- func (s *Store) KeepDraft(ctx context.Context, d server.Draft, max int) error
- func (s *Store) KeepOutcome(ctx context.Context, id string, at time.Time, outcome json.RawMessage) error
- func (s *Store) KeepToDo(ctx context.Context, td server.ToDo) error
- func (s *Store) KeepUpload(ctx context.Context, u server.Upload, max int) (string, error)
- func (s *Store) KeptVersions(ctx context.Context) ([]server.TicketCount, error)
- func (s *Store) LastImport(ctx context.Context) (server.Record, error)
- func (s *Store) LatestOrganization(ctx context.Context) (server.OrgSnapshot, error)
- func (s *Store) LetGoUploads(ctx context.Context, before time.Time, limit int) ([]server.Upload, error)
- func (s *Store) Lock(ctx context.Context, ticket string) (context.Context, func(), error)
- func (s *Store) Mine(ctx context.Context, person string, q server.MineQuery) ([]server.TicketRecord, error)
- func (s *Store) Moves(ctx context.Context, ticket string) ([]server.MoveRecord, error)
- func (s *Store) OpenUploads(ctx context.Context, person string) (int, error)
- func (s *Store) Operation(ctx context.Context, person, key string) (server.OperationRecord, error)
- func (s *Store) Organization(ctx context.Context, id string) (server.OrgSnapshot, error)
- func (s *Store) PutOffTimer(ctx context.Context, k server.TimerKey, try time.Time) error
- func (s *Store) Record(ctx context.Context, id string) (server.Record, error)
- func (s *Store) Records(ctx context.Context, q server.RecordQuery) ([]server.Line, error)
- func (s *Store) Renew(ctx context.Context, b server.Begun) error
- func (s *Store) RetryToDo(ctx context.Context, id string, try time.Time, why string) error
- func (s *Store) Revoke(ctx context.Context, session string, until time.Time) error
- func (s *Store) Revoked(ctx context.Context, session string) (bool, error)
- func (s *Store) Save(ctx context.Context, m *server.Move) error
- func (s *Store) SaveChange(ctx context.Context, c *server.Change) error
- func (s *Store) SaveOrganization(ctx context.Context, o server.OrgSnapshot) error
- func (s *Store) Starts(ctx context.Context) ([]server.Start, error)
- func (s *Store) Ticket(ctx context.Context, id string) (server.TicketRecord, error)
- func (s *Store) Tickets(ctx context.Context, q server.TicketsQuery) ([]server.TicketRecord, error)
- func (s *Store) Timers(ctx context.Context, ticket string) ([]server.Timer, error)
- func (s *Store) ToDoItem(ctx context.Context, id string) (server.ToDo, error)
- func (s *Store) ToDoList(ctx context.Context, ticket string) ([]server.ToDo, error)
- func (s *Store) Trial(ctx context.Context) (any, func(), error)
- func (s *Store) UploadOf(ctx context.Context, person, key string) (string, error)
- func (s *Store) UploadsDeleted(ctx context.Context, ids []string) error
- func (s *Store) Waiting(ctx context.Context, people []string, q server.WaitingQuery) ([]server.TicketRecord, error)
- type Tx
Constants ¶
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 ¶
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a store on PostgreSQL.
func New ¶
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 ¶
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 ¶
BundleArchive reads a bundle's archive, or ErrNotFound.
func (*Store) Bundles ¶
Bundles reads every bundle the store keeps, without their archives, in the order they were uploaded.
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 ¶
CountWaiting counts the tickets that wait for the person, by kind.
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) 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 ¶
ForgetDrafts forgets up to limit drafts kept before `before`, the oldest first.
func (*Store) ForgetOperations ¶
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 ¶
Imports answers the times of the imports that added a snapshot at or after since.
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 ¶
KeepToDo keeps a thing to do that no move holds; one with the same ID is left as it is.
func (*Store) KeepUpload ¶
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 ¶
KeptVersions counts the tickets of every version the store keeps any of, by kind, version and status.
func (*Store) LastImport ¶
LastImport reads the latest record of an import from the source.
func (*Store) LatestOrganization ¶
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 ¶
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) OpenUploads ¶
OpenUploads counts a person's uploads that no ticket holds and that are not let go.
func (*Store) Organization ¶
Organization reads a snapshot.
func (*Store) PutOffTimer ¶
PutOffTimer keeps a timer to be tried again later.
func (*Store) Revoke ¶
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) SaveChange ¶
SaveChange writes a change an administrator made, all or nothing (server.Change).
func (*Store) SaveOrganization ¶
SaveOrganization keeps a snapshot and makes it the latest, under the lock every making of a latest takes (orgLock).
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) UploadsDeleted ¶
UploadsDeleted records that the files of uploads let go are deleted.
type Tx ¶
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.