Documentation
¶
Overview ¶
Package store is api's database: its schema, the migrations that make it, the pool requests take their connections from, and the transaction a write under an account runs in (R29).
Index ¶
- Constants
- Variables
- func AllowCountry(ctx context.Context, db Querier, country string) (bool, error)
- func Answers(ctx context.Context, db pgx.Tx, profileID, attemptID string) ([][]byte, error)
- func AppendEvidence(ctx context.Context, tx pgx.Tx, profileID string, o Owed, evidence []byte, ...) (int64, error)
- func AskedQuestions(ctx context.Context, db pgx.Tx, profileID, attemptID string) ([]string, error)
- func AsksBeforeShowing(ctx context.Context, db Querier, profileID string) (bool, error)
- func AttemptTask(ctx context.Context, db Querier, profileID, attemptID string) (digest, taskID string, err error)
- func BeginAttempt(ctx context.Context, tx pgx.Tx, profileID string, a NewAttempt, at time.Time) (string, error)
- func BeginLessonRun(ctx context.Context, tx pgx.Tx, profileID string, r NewRun, at time.Time) (string, error)
- func CanonicalID(id string) bool
- func ChoiceBegun(ctx context.Context, db Querier, profileID, choiceID string) (bool, error)
- func ClearAccount(ctx context.Context, tx pgx.Tx, accountID string) error
- func CloseAbandonedAttempts(ctx context.Context, db Querier, before, at time.Time) (int64, error)
- func CloseAttempt(ctx context.Context, tx pgx.Tx, profileID, attemptID, reason string, ...) error
- func ConnectModule(ctx context.Context, db Querier, profileID, moduleID string) error
- func Countries(ctx context.Context, db Lister) ([]string, error)
- func CountryAccepted(ctx context.Context, db Querier, country string) (bool, error)
- func CreateAccount(ctx context.Context, db Beginner, uid string, codeSHA256 []byte) (string, error)
- func CreateInvite(ctx context.Context, db Querier, codeSHA256 []byte, tariff string) error
- func DeleteAccountRow(ctx context.Context, db Beginner, accountID string) error
- func DeleteProfileRows(ctx context.Context, tx pgx.Tx, profileID string) error
- func DisconnectModule(ctx context.Context, db Querier, profileID, moduleID string) error
- func DropConsentRecords(ctx context.Context, db Querier, before time.Time) (int64, error)
- func DropKeys(ctx context.Context, db Querier, before time.Time) (int64, error)
- func DropRecord(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time) error
- func EndAbandonedRuns(ctx context.Context, db Querier, before, at time.Time) (int64, error)
- func EndLessonRun(ctx context.Context, tx pgx.Tx, profileID, runID, reason string, at time.Time) error
- func EndedSegments(ctx context.Context, tx pgx.Tx, profileID, runID string) ([]int, error)
- func ExplainRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, ...) error
- func FinishRecord(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time, ...) error
- func GiveRequested(ctx context.Context, tx pgx.Tx, profileID, attemptID string, ...) error
- func GiveStepTechniques(ctx context.Context, tx pgx.Tx, profileID, attemptID string, at time.Time) error
- func HasOwnerProfile(ctx context.Context, tx pgx.Tx, accountID string) (bool, error)
- func HaveAccounts(ctx context.Context, db Lister, uids []string) (map[string]bool, error)
- func HeldMapSkill(ctx context.Context, db Querier, profileID string) (string, error)
- func HoldAccount(ctx context.Context, tx pgx.Tx, accountID string) error
- func HoldAttemptRun(ctx context.Context, tx pgx.Tx, profileID, attemptID string) error
- func HoldPin(ctx context.Context, tx pgx.Tx, accountID string) (pin.State, error)
- func JournalModules(ctx context.Context, tx pgx.Tx, profileID string) ([]string, error)
- func LastAttempt(ctx context.Context, db Querier, profileID, attemptID string) (bool, error)
- func LastSubmission(ctx context.Context, db Querier, profileID, attemptID string) ([]byte, bool, error)
- func MarkDeleting(ctx context.Context, tx pgx.Tx, accountID string) error
- func MarkIdle(ctx context.Context, tx pgx.Tx, accountID string, before time.Time) (bool, error)
- func Migrate(ctx context.Context, url string) (applied int, version int64, err error)
- func MigrateFiles(ctx context.Context, url string, files fs.FS) (applied int, version int64, err error)
- func ModuleConnected(ctx context.Context, db Querier, profileID, moduleID string) (bool, error)
- func Open(ctx context.Context, url string) (*pgxpool.Pool, error)
- func ProfileGrade(ctx context.Context, db Querier, profileID string) (*int, error)
- func ProfileIdle(ctx context.Context, tx pgx.Tx, accountID, profileID string, before time.Time) (bool, error)
- func ProfileOf(ctx context.Context, db Querier, accountID, profileID string) (bool, time.Time, error)
- func ProfilesOwingEvidence(ctx context.Context, db Lister, digests []string, after string, n int) ([]string, error)
- func ProfilesThere(ctx context.Context, db Lister, ids []string) (map[string]string, error)
- func RecordDone(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, ...) error
- func RecordGoing(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, ...) (time.Time, error)
- func RemoveCountry(ctx context.Context, db Querier, country string) (bool, error)
- func RunLesson(ctx context.Context, db Querier, profileID, runID string) (string, error)
- func SubmissionAnswer(ctx context.Context, db Querier, profileID, submissionID string) ([]byte, error)
- func Submit(ctx context.Context, tx pgx.Tx, profileID, attemptID string, ...) (string, error)
- func TodayByUTC(on, now time.Time) bool
- func TouchAccount(ctx context.Context, db Querier, accountID string) error
- func TouchLessonRun(ctx context.Context, tx pgx.Tx, profileID, runID string, at time.Time) error
- func TouchProfile(ctx context.Context, db Querier, profileID string) error
- func WaitingConsents(ctx context.Context, tx pgx.Tx, accountID string) (int, error)
- func WriteChoice(ctx context.Context, tx pgx.Tx, profileID string, c NewChoice, at time.Time) (string, error)
- func WritePin(ctx context.Context, tx pgx.Tx, accountID string, state pin.State) error
- func WriteProfile(ctx context.Context, tx pgx.Tx, p Profile) error
- func WriteRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, w Words) error
- func WriteSkillState(ctx context.Context, tx pgx.Tx, profileID string, s SkillState) error
- func WriteUnderAccount(ctx context.Context, db Beginner, accountID string, fn func(pgx.Tx) error) error
- type Account
- type AccountRef
- type Attempt
- type Beginner
- type ChildConsent
- type Choice
- type ClosedAttempt
- type ConnectedModule
- type Consent
- type Cursor
- type Entry
- type Issued
- type KeyRecord
- type KeyTarget
- type Learner
- type LessonRun
- type Lister
- type MadeChoice
- type Mark
- type ModuleChoices
- type NewAttempt
- type NewChoice
- type NewRun
- type OpenAttempt
- type OpenLessonRun
- type Owed
- type Profile
- func CreateChildProfile(ctx context.Context, tx pgx.Tx, accountID string, c Consent, p Profile) (Profile, error)
- func CreateOwnerProfile(ctx context.Context, tx pgx.Tx, accountID string, p Profile) (Profile, error)
- func ProfileFor(ctx context.Context, tx pgx.Tx, accountID, profileID string) (Profile, error)
- type ProfileRef
- type Querier
- type Record
- type Run
- type Rung
- type SkillState
- type Solution
- type TxBeginner
- type View
- type Words
Constants ¶
const ( ConsentWaiting = "waiting" ConsentConfirmed = "confirmed" )
The states of a consent.
const ( // SourceModel is the tutor's question, which passed the leak check and the // form check. SourceModel = "model" // SourceFallback is the rung's fallback text. SourceFallback = "fallback" )
The sources of a rung's words, as the schema writes them (R05).
const ( // KeyGoing is a request that is still going. KeyGoing = "going" // KeyDone is a request done, whose answer the record holds. KeyDone = "done" )
The states of a record of an idempotency key.
const ( RunPassed = "passed" RunUnchecked = "unchecked" RunNotSuitable = "not_suitable" RunAbandoned = "abandoned" )
The end reasons of a lesson run, as the schema writes them.
const AbandonedAfter = 7 * 24 * time.Hour
AbandonedAfter is how long an open attempt goes with no action before it is abandoned (R10): the check of a request closes it then, and so does the daily job.
const ConsentByOwnerStatement = "owner_statement"
The ways a consent was given (R36). The owner's own is the statement that they are 18 or older, dated with the account (R118 spec).
const RunAbandonedAfter = 30 * 24 * time.Hour
RunAbandonedAfter is how long an open lesson run goes with no request on it or its attempts before it is abandoned (R13).
Variables ¶
var ( // ErrNotFound is an attempt, a lesson run or an engine's choice that the // profile does not have: another profile's is the same (R04). ErrNotFound = errors.New("store: the profile has no such row") // ErrChoiceBegun is an engine's choice of a task that has begun an attempt // already (contract, BeginAttempt). ErrChoiceBegun = errors.New("store: the choice has begun an attempt already") )
The refusals of the rows of an attempt.
var ( // ErrAccountExists is a user who has an account already. ErrAccountExists = errors.New("store: the account exists") // ErrCodeNotAccepted is a code that is not there, or was redeemed. ErrCodeNotAccepted = errors.New("store: the code is not accepted") )
The refusals of the creation of an account (R04; contract, CreateAccount).
var ( // ErrProfileExists is a profile there already: the owner's second, or the // profile of a consent that has one. ErrProfileExists = errors.New("store: the profile exists") // ErrNoProfile is a profile that is not the account's. ErrNoProfile = errors.New("store: no such profile") )
The refusals of a profile (contract, AccountService).
var ( // ErrNoAccount is a write under an account that is not there. ErrNoAccount = errors.New("store: no account") // ErrAccountDeleting is a write under an account marked "deleting" (R21). ErrAccountDeleting = errors.New("store: the account is being deleted") )
The refusals of a write under an account.
var ErrNoConsent = errors.New("store: no such consent")
ErrNoConsent is a consent for a child that is not the account's.
var ErrRecordGone = errors.New("store: the key's record going is gone")
ErrRecordGone is a record going that is no longer there, or no longer this request's, when its request comes to finish: a repeat found it fallen and went again.
var ErrRunBegun = errors.New("store: the profile has an open run of the lesson")
ErrRunBegun is a lesson run that could not begin because another request began one meanwhile — the profile's open run of the lesson, or the run of the same choice: the request reads it again.
Functions ¶
func AllowCountry ¶ added in v0.1.7
AllowCountry adds country to the list, and says whether it was not there.
func Answers ¶ added in v0.1.17
Answers is the answers of the attempt's submissions with a verdict, in order: the ladder finds in them the wrong answer that gave a rung, and its answer slot.
func AppendEvidence ¶ added in v0.1.18
func AppendEvidence(ctx context.Context, tx pgx.Tx, profileID string, o Owed, evidence []byte, at time.Time) (int64, error)
AppendEvidence adds the evidence of the profile's attempt to its journal at at, under the number after the journal's last, and gives the number. The caller holds the profile's row of the cache, which orders the numbers (R06).
func AskedQuestions ¶ added in v0.1.17
AskedQuestions is the tutor's questions on the attempt so far, in order: the words of its rungs that came of a model, which every call of the words gets, so as not to ask them again (R10).
func AsksBeforeShowing ¶ added in v0.1.17
AsksBeforeShowing says whether the profile's setting "ask before showing" is on: a child's, and on by default (R09).
func AttemptTask ¶ added in v0.1.17
func AttemptTask(ctx context.Context, db Querier, profileID, attemptID string) (digest, taskID string, err error)
AttemptTask is the package and the task of the profile's attempt, read with no lock: what an attempt is of never changes, so a request may choose its way by it before it holds the attempt.
func BeginAttempt ¶ added in v0.1.15
func BeginAttempt(ctx context.Context, tx pgx.Tx, profileID string, a NewAttempt, at time.Time) (string, error)
BeginAttempt begins a at at, in tx, once the profile's open attempt is closed: the profile has one open attempt (R10). A choice that has begun an attempt already is ErrChoiceBegun.
func BeginLessonRun ¶ added in v0.1.17
func BeginLessonRun(ctx context.Context, tx pgx.Tx, profileID string, r NewRun, at time.Time) (string, error)
BeginLessonRun begins the run r at at, in tx, and gives its ID. A profile that has an open run of the lesson already is ErrRunBegun, and tx can go on: the insert runs in a savepoint of its own.
func CanonicalID ¶ added in v0.1.7
CanonicalID says whether id is a UUID as the database writes one: lowercase, with its dashes. Any other ID names no row, and nothing is asked of it: OpenFGA would refuse the colons of urn:uuid:, and hold no tuple of an uppercase one.
func ChoiceBegun ¶ added in v0.1.15
ChoiceBegun says whether the engine's choice has begun an attempt.
func ClearAccount ¶ added in v0.1.8
ClearAccount deletes, in the transaction that marked the account "deleting", all the database keeps of it but its ID, its UID and the time of the mark (R21; architecture 3.10, step 1): every profile as DeleteProfileRows deletes one, the consents that wait and the adults', the records of its keys, its fields, and the binding of its invite code — the code stays redeemed.
func CloseAbandonedAttempts ¶ added in v0.1.14
CloseAbandonedAttempts closes "abandoned", at at, the open attempts with no action since before, a batch at a time, and says how many it closed (R10). One clock judges the term and dates the close: the pass's. An attempt a request holds is skipped, and the next pass finds it if it is still idle; the term is checked again on the row the UPDATE takes, so an action that came meanwhile keeps the attempt open. The close moves no date of the profile's activity.
func CloseAttempt ¶ added in v0.1.15
func CloseAttempt(ctx context.Context, tx pgx.Tx, profileID, attemptID, reason string, at time.Time) error
CloseAttempt closes the open attempt with reason at at; one closed already keeps its close.
func ConnectModule ¶ added in v0.1.13
ConnectModule connects the module to the profile, now; a module connected already keeps the time it was connected. A profile that is gone is ErrNoProfile: the row refers to it.
func CountryAccepted ¶ added in v0.1.7
CountryAccepted says whether the deployment takes learners from country (R118, R119 spec; R36). None is taken until the operator adds it.
func CreateAccount ¶ added in v0.1.5
CreateAccount creates the account of the sign-in service's UID by the code of codeSHA256, with the owner's statement that they are 18 or older dated now, and returns its ID (R04; architecture 3.1, steps 2 and 3). It is one transaction, in the order of the contract: an account the UID has already is ErrAccountExists — or ErrAccountDeleting, when it is marked — before the code is looked at, so that a repeat is not refused for the code it redeemed; then a code not there or redeemed is ErrCodeNotAccepted, and no account is left. The code is bound to the account, and its tariff passes to it.
Two creations race safely. Two by one UID: the second waits on the UID's unique index and finds the first's account. Two for one code: the second waits on the code's row and finds it redeemed. Either way, a first one that rolls back leaves the second to go on.
func CreateInvite ¶ added in v0.1.5
CreateInvite keeps a new invite code by its SHA-256 alone, with the tariff it passes to the account that redeems it (R04, R11).
func DeleteAccountRow ¶ added in v0.1.8
DeleteAccountRow is the last step of the deletion of an account (R21; architecture 3.10, step 4): in one transaction, it clears again what a row written late may have left, and deletes the account's row. An account that is not there is deleted already.
func DeleteProfileRows ¶ added in v0.1.8
DeleteProfileRows deletes, in the transaction that holds the profile, all that the database keeps of it (R21; architecture 3.10): its consent — for a child into its minimal record, an adult's whole — its records of idempotency keys, and the profile. What epic E3 keeps of a profile goes with it by its keys.
func DisconnectModule ¶ added in v0.1.13
DisconnectModule disconnects the module from the profile; a module not connected changes nothing.
func DropConsentRecords ¶ added in v0.1.11
DropConsentRecords deletes the minimal records of consents for children whose account or profile was deleted before before, a batch at a time, and says how many went: a record is kept 5 years after the deletion and then erased (R117 spec; R21). A stop between batches keeps what went.
func DropKeys ¶ added in v0.1.9
DropKeys deletes the records of idempotency keys made before before, a batch at a time, and says how many went: a key is kept for a day (R17). A stop between batches keeps what went.
func DropRecord ¶ added in v0.1.17
DropRecord deletes the account's record going made at made — of a request refused after its call, which records nothing — or, with made zero, whichever is going: of a request that fell, which a repeat runs again.
func EndAbandonedRuns ¶ added in v0.1.14
EndAbandonedRuns ends "abandoned", at at, the open lesson runs with no action since before, a batch at a time, as CloseAbandonedAttempts closes attempts (R13): no request on the run, and no action on its attempts, which is the run's too.
func EndLessonRun ¶ added in v0.1.17
func EndLessonRun(ctx context.Context, tx pgx.Tx, profileID, runID, reason string, at time.Time) error
EndLessonRun ends the profile's open run with reason at at; one ended already keeps its end. A run that ends "not suitable" closes its open attempt "not suitable" with it (R10, R13).
func EndedSegments ¶ added in v0.1.17
EndedSegments is the places of the run's task segments that have ended, in order: those whose attempt was closed by a correct answer, by the solution shown or by "Done" (R13).
func ExplainRung ¶ added in v0.1.17
func ExplainRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, read, other Words, at time.Time) error
ExplainRung records, at at, that "explain differently" was asked for on the attempt's rung, and the words that came of it. A rung whose words never came is recorded with read, the words the learner read before: its fallback text.
func FinishRecord ¶ added in v0.1.17
func FinishRecord(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time, target KeyTarget) error
FinishRecord turns the account's record going, the one made at made, into done with its target, in the transaction of what the request writes after its call.
func GiveRequested ¶ added in v0.1.17
func GiveRequested(ctx context.Context, tx pgx.Tx, profileID, attemptID string, techniques, leading bool, at time.Time) error
GiveRequested records, at at, that a hint asked for gave the techniques of the attempt's task, when techniques — it has some —, and its leading question, when leading, each the first time it did, and that the attempt's last action is at (R47).
func GiveStepTechniques ¶ added in v0.1.15
func GiveStepTechniques(ctx context.Context, tx pgx.Tx, profileID, attemptID string, at time.Time) error
GiveStepTechniques records that the techniques of the attempt's task were given at a step, the first time they were, and that the attempt's last action is at.
func HasOwnerProfile ¶ added in v0.1.7
HasOwnerProfile says whether the account has the owner's profile.
func HaveAccounts ¶ added in v0.1.9
HaveAccounts is the UIDs, of uids, that have an account, marked or not: the daily job removes the users of the sign-in service that have none (R21).
func HeldMapSkill ¶ added in v0.1.19
HeldMapSkill is the skill chosen on the skill map that the profile's last choice holds, empty when it holds none: a choice from the map holds until the learner asks for something else (R107 spec).
func HoldAccount ¶ added in v0.1.7
HoldAccount takes the account's row FOR NO KEY UPDATE in tx: what a request under an idempotency key holds first, so that a repeat beside it waits and finds its record. The lock conflicts with itself and not with FOR KEY SHARE, so the other writes under the account do not wait for it (R29, R35).
func HoldAttemptRun ¶ added in v0.1.17
HoldAttemptRun holds FOR UPDATE, in tx, the lesson run of the profile's attempt, when it is one of a run, or of the profile's open attempt when attemptID is empty: a request on an attempt holds its run first, as the requests on the run do, so that the close of the attempt, which may end the run, takes the two rows in the order every request takes them (R48).
func HoldPin ¶ added in v0.1.6
HoldPin takes the account's row FOR NO KEY UPDATE and reads its PIN. The lock conflicts with itself and not with FOR KEY SHARE: the requests of the PIN of one account — from two devices, or a repeat beside its first — go one after the other, and its count loses no wrong PIN, while the other writes under the account do not wait for them (R29).
func JournalModules ¶ added in v0.1.18
JournalModules is the modules of the profile's journal, by ID.
func LastAttempt ¶ added in v0.1.17
LastAttempt says whether the attempt is the last the profile began: the words after a correct answer are given while the profile has begun no other (R09).
func LastSubmission ¶ added in v0.1.15
func LastSubmission(ctx context.Context, db Querier, profileID, attemptID string) ([]byte, bool, error)
LastSubmission is the answer of the attempt's last submission with a verdict, and whether it has one.
func MarkDeleting ¶
MarkDeleting takes the account's row FOR UPDATE in tx and marks it "deleting", the first step of the deletion of an account (R21). FOR UPDATE is what waits for every write that holds the row by FOR KEY SHARE: a plain UPDATE of the mark takes FOR NO KEY UPDATE, which does not conflict with FOR KEY SHARE, and would let a write that does not touch the row commit after the mark. The deletion clears the account's data in the same tx, after this.
func MarkIdle ¶ added in v0.1.9
MarkIdle marks the account "deleting" in tx, as MarkDeleting does, only if it still had no request since before, and says whether it did. The term is read under the row's lock: a request that wrote today's date while the job chose the account keeps it, since FOR UPDATE waits for that write and reads the row again (R21; П-9).
func Migrate ¶
Migrate applies to the database at url every migration of api it has not had, and returns how many it applied and the version the schema is at (R29).
func MigrateFiles ¶ added in v0.1.2
func MigrateFiles(ctx context.Context, url string, files fs.FS) (applied int, version int64, err error)
MigrateFiles applies the migrations in files — api's, or OpenFGA's for the rights (R31) — to the database at url that it has not had. url is the direct connection: goose holds an advisory lock of the session while it migrates, so that two runs never migrate at once, and Neon's pooler keeps no session (R29). Each migration runs in a transaction of its own, but one its file says may not.
func ModuleConnected ¶ added in v0.1.15
ModuleConnected says whether the module is connected to the profile.
func Open ¶
Open is a pool of connections to the database at url. The pool takes them as it needs them, and pgx keeps its prepared statements by the protocol, which Neon's pooler keeps too (R29).
func ProfileGrade ¶ added in v0.1.18
ProfileGrade is the profile's school grade, nil when it names none.
func ProfileIdle ¶ added in v0.1.9
func ProfileIdle(ctx context.Context, tx pgx.Tx, accountID, profileID string, before time.Time) (bool, error)
ProfileIdle holds the account's profile FOR UPDATE in tx if it was still active last before before, and says whether it was: a request that touched it today while the job chose it keeps it (П-9).
func ProfileOf ¶ added in v0.1.4
func ProfileOf(ctx context.Context, db Querier, accountID, profileID string) (bool, time.Time, error)
ProfileOf says whether the account has the profile, and the date of the profile's last activity. It is read after the right to the profile, never before (architecture 3.1): a tuple whose profile is gone — dangling, R21 — gives a right to nothing.
func ProfilesOwingEvidence ¶ added in v0.1.18
func ProfilesOwingEvidence(ctx context.Context, db Lister, digests []string, after string, n int) ([]string, error)
ProfilesOwingEvidence is up to n of the profiles with an attempt that owes its evidence, on the packages digests names, by ID after the ID after, for the daily job.
func ProfilesThere ¶ added in v0.1.9
ProfilesThere is the profiles, of ids, that are there, each with its account: a tuple whose profile is not, or is another account's, is dangling (R21). An ID that is no UUID as the database writes one names no row, and is not asked.
func RecordDone ¶ added in v0.1.6
func RecordDone(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, target KeyTarget) error
RecordDone records a request done under the account's key, with its target, in the transaction of the action, so that the action and its record commit together or not at all. A request on the account itself names no profile.
func RecordGoing ¶ added in v0.1.17
func RecordGoing(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, target KeyTarget) (time.Time, error)
RecordGoing records a request under the account's key as going, with what it acts on, and commits with the checks before its call of AI: a repeat beside it is "still going" until it is done, or until it outlives the longest a request may run (R17). It gives when the record was made, by the database's clock: the mark by which the request finishes or drops its own record, and never a repeat's that took its place.
func RemoveCountry ¶ added in v0.1.7
RemoveCountry takes country off the list, and says whether it was there. The profiles of the country stay: a new one is refused.
func RunLesson ¶ added in v0.1.17
RunLesson is the full ID of the lesson of the profile's run, read with no lock: what a run is of never changes.
func SubmissionAnswer ¶ added in v0.1.15
func SubmissionAnswer(ctx context.Context, db Querier, profileID, submissionID string) ([]byte, error)
SubmissionAnswer is the answer of the profile's submission by its ID.
func Submit ¶ added in v0.1.15
func Submit(ctx context.Context, tx pgx.Tx, profileID, attemptID string, answer, observation []byte, wrong bool, at time.Time) (string, error)
Submit records a submission with a verdict of the attempt, by its answer and the observation of its work, as the attempt's next, and counts it a wrong answer when wrong: the attempt's last action is at. It gives the submission's ID.
func TodayByUTC ¶ added in v0.1.7
TodayByUTC says whether on is the date of now by UTC: the date written once a day, of an account or a profile, that needs no writing again.
func TouchAccount ¶ added in v0.1.4
TouchAccount writes today, by UTC, as the date of the account's last request, once a day at most: the date the account is deleted by after 12 months with no request (R05, R33). A plain UPDATE takes FOR NO KEY UPDATE, which the writes under the account, by FOR KEY SHARE, do not wait for.
func TouchLessonRun ¶ added in v0.1.17
TouchLessonRun records a request on the profile's open run at at: its last action (R13). A request on an attempt of the run is its attempt's action, which the run's last action reads too.
func TouchProfile ¶ added in v0.1.7
TouchProfile writes today, by UTC, as the date of the profile's last activity, once a day at most: the date a profile is deleted by after 12 months with none (П-9; R36), as TouchAccount writes the account's.
func WaitingConsents ¶ added in v0.1.11
WaitingConsents is how many consents for a child wait under the account. It takes no lock: its caller holds the account's row FOR NO KEY UPDATE, by HoldAccount, as every request under a key does, so that two requests beside each other count one after the other (R35, R36).
func WriteChoice ¶ added in v0.1.19
func WriteChoice(ctx context.Context, tx pgx.Tx, profileID string, c NewChoice, at time.Time) (string, error)
WriteChoice writes the profile's choice c, made at at, and gives its ID.
func WritePin ¶ added in v0.1.6
WritePin writes the account's PIN as state has it: after an action that left one set, which every action of the PIN does.
func WriteProfile ¶ added in v0.1.7
WriteProfile writes the settings of p, the profile ProfileFor held: what an adult changes, and nothing the profile was created with.
func WriteRung ¶ added in v0.1.17
func WriteRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, w Words) error
WriteRung records the words of the attempt's rung, the first that came for it.
func WriteSkillState ¶ added in v0.1.18
WriteSkillState writes the profile's cache: its state, the mark it was computed on and the number of the last evidence it holds.
func WriteUnderAccount ¶
func WriteUnderAccount(ctx context.Context, db Beginner, accountID string, fn func(pgx.Tx) error) error
WriteUnderAccount runs fn in a transaction that holds the account's row by FOR KEY SHARE and has found it not marked "deleting" (R21). The deletion of an account takes the row FOR UPDATE, so a write that got here before the mark commits before the mark is set, and one after it sees the mark and writes nothing. FOR KEY SHARE, rather than FOR SHARE, lets fn itself update fields of the row — the date of the request, the PIN's count — without locking out a neighbouring request of the same account. The transaction commits when fn returns nil, and rolls back on its error, which it returns as it is.
Types ¶
type Account ¶ added in v0.1.4
type Account struct {
// ID is the account's own ID, the subject of the rights.
ID string
// Deleting says the account is marked "deleting" (R21).
Deleting bool
// LastRequestOn is the date, by UTC, of the account's last request; zero if
// none was written yet.
LastRequestOn time.Time
}
Account is what a request knows of the account of its token (R04).
func AccountByUID ¶ added in v0.1.4
AccountByUID is the account of the sign-in service's UID, or ErrNoAccount.
type AccountRef ¶ added in v0.1.9
AccountRef is an account the daily job works on: its ID and its UID at the sign-in service.
func IdleAccounts ¶ added in v0.1.9
func IdleAccounts(ctx context.Context, db Lister, before time.Time, after string, limit int) ([]AccountRef, error)
IdleAccounts is up to limit accounts not marked whose last request was before before, whose ID comes after after, by ID: those the daily job deletes after 12 months without a request (П-9). An account with no date of a request yet is none of them.
func MarkedBefore ¶ added in v0.1.9
func MarkedBefore(ctx context.Context, db Lister, before time.Time, after string, limit int) ([]AccountRef, error)
MarkedBefore is up to limit accounts marked "deleting" before before, whose ID comes after after — empty for the first page —, by ID: the marks a request left unfinished, which the daily job finishes (R21). The job pages by the last ID it saw, so that an account it fails on is not chosen again in the same pass.
type Attempt ¶ added in v0.1.15
type Attempt struct {
ID string
PackageDigest string
ModuleID string
ModuleVersion string
FormatVersion string
ModuleKit string
TaskID string
Seed uint64
Instance *int
ChoiceID *string
LessonRunID *string
Segment *int
PreviousID *string
LastActionAt time.Time
CloseReason *string
WrongAnswers int
StepTechniques bool
// RequestedTechniques and LeadingQuestion say whether a hint asked for gave
// the task's techniques, and its leading question (R47).
RequestedTechniques bool
LeadingQuestion bool
}
Attempt is an attempt's row, as the requests on it read it.
func HoldAttempt ¶ added in v0.1.15
HoldAttempt is the profile's attempt by its ID, its row held FOR UPDATE in tx, so that the requests on one attempt go one after the other; ErrNotFound when the profile has none.
type ChildConsent ¶ added in v0.1.5
type ChildConsent struct {
ID string
AgeCategory string
Country string
// State is "waiting" or "confirmed".
State string
}
ChildConsent is a consent for a child that waits for its profile.
func CreateChildConsent ¶ added in v0.1.7
func CreateChildConsent(ctx context.Context, tx pgx.Tx, accountID, category, country string) (ChildConsent, error)
CreateChildConsent records a consent for a child that waits, under the account, with the age category and the country alone: no pseudonym, no other field of the profile, and not the age in years (privacy 3.3 spec; R36).
type Choice ¶ added in v0.1.15
Choice is what an engine's choice names, as far as the beginning of an attempt or a lesson run reads it: its kind, its module, and the task of a choice of a task or the lesson's local ID of a choice of a lesson.
type ClosedAttempt ¶ added in v0.1.19
type ClosedAttempt struct {
ID string
PackageDigest string
ModuleID string
TaskID string
CloseReason string
ClosedAt time.Time
LessonID *string
ReasonCode *int
Evidence []byte
}
ClosedAttempt is a closed attempt of the profile as the engine's input reads it: what it was of, how and when it closed, the full ID of the lesson of its run, the reason code of the choice that began it — of its run's, for a segment; none for an attempt begun again or by a choice written before the codes —, and its evidence, when the journal has it.
func ClosedAttempts ¶ added in v0.1.19
ClosedAttempts is the profile's closed attempts, the last closed first.
type ConnectedModule ¶ added in v0.1.13
ConnectedModule is a module connected to a profile (R07): its ID and when it was connected, with no version.
func ConnectedModules ¶ added in v0.1.13
ConnectedModules is the modules connected to the profile, in the order they were connected, and by ID among those connected at one time.
type Consent ¶ added in v0.1.7
type Consent struct {
ChildConsent
// ProfileID is the profile created by it, or empty while there is none.
ProfileID string
}
Consent is a consent for a child, as its profile is created by it.
type Cursor ¶ added in v0.1.18
Cursor is where a page of the progress goes on from: the attempt last on the page before, by its beginning and its ID.
type Entry ¶ added in v0.1.18
type Entry struct {
Seq int64
AttemptID string
PackageDigest string
ModuleID string
ClosedAt time.Time
Evidence []byte
}
Entry is a row of a profile's journal of evidence: its number, its attempt, the package and the module of the attempt, when the attempt closed, and the evidence as learner-model's codec gives it.
type Issued ¶ added in v0.1.19
Issued is when a skill was last handed out by a choice, by its full ID.
type KeyRecord ¶ added in v0.1.6
type KeyRecord struct {
Method string
Fingerprint string
State string
Response []byte
SubmissionID string
// Age is how long ago the record was made, by the database's clock: a record
// still going past the longest a request may run is of a request that fell.
Age time.Duration
}
KeyRecord is what is recorded of a request under its idempotency key (R17, R35): its method, its fingerprint, its state and, once done, its answer — or, for an answer that holds what the learner sent, the submission it recorded.
type KeyTarget ¶ added in v0.1.15
KeyTarget is what a request done under a key acted on, and what its record holds of the answer: the profile and the attempt it acted on, when it did, and either the answer or the submission whose answer a repeat gets (architecture 3.2).
type Learner ¶ added in v0.1.13
Learner is what a learning request reads of its profile, in one query: the age category, by which a module's audience suits it (R07), and whether its consent is confirmed: a profile has one consent at most, and a consent that waits has no profile (architecture 3.1, step 5; R116 spec).
type LessonRun ¶ added in v0.1.17
type LessonRun struct {
ID string
LessonID string
ModuleID string
ModuleVersion string
PackageDigest string
ChoiceID string
LastActionAt time.Time
EndReason *string
}
LessonRun is a lesson run's row, as the requests on it read it (R13).
func HoldLessonRun ¶ added in v0.1.17
HoldLessonRun is the profile's lesson run by its ID, its row held FOR UPDATE in tx, so that the requests on one run go one after the other; ErrNotFound when the profile has none.
type Lister ¶ added in v0.1.7
Lister is what a list is read from: a pool, a connection or a transaction.
type MadeChoice ¶ added in v0.1.19
MadeChoice is a choice written: its ID and kind, and, beside nothing to give, whether its answer said "not admitted".
func ChoiceAfterAttempt ¶ added in v0.1.19
func ChoiceAfterAttempt(ctx context.Context, db Querier, profileID, attemptID string) (MadeChoice, bool, error)
ChoiceAfterAttempt is the choice the close of the profile's attempt gave as what comes next, and whether it gave one: a repeat of the request that closed it gives it again.
func ChoiceAfterRun ¶ added in v0.1.19
func ChoiceAfterRun(ctx context.Context, db Querier, profileID, runID string) (MadeChoice, bool, error)
ChoiceAfterRun is the choice the end of the profile's lesson run gave, and whether it gave one.
type Mark ¶ added in v0.1.18
Mark is what the cache of a profile's skill state was computed on (R06): the version of learner-model, the release of modules and the window of the format's versions. An empty field is a cache never written.
type ModuleChoices ¶ added in v0.1.19
ModuleChoices is how many choices of a module the profile had, a lesson's counted once.
func ChoicesByModule ¶ added in v0.1.19
ChoicesByModule is how many choices the profile had of each module.
type NewAttempt ¶ added in v0.1.15
type NewAttempt struct {
PackageDigest string
ModuleID string
ModuleVersion string
FormatVersion string
ModuleKit string
TaskID string
Seed uint64
Instance *int
ChoiceID *string
PreviousID *string
// LessonRunID and Segment are the run and the place of the segment of an
// attempt of a lesson's task.
LessonRunID *string
Segment *int
}
NewAttempt is what an attempt begins with: its package, the versions its verdict repeats by, its task, seed and instance, and one of the three ways it begins.
type NewChoice ¶ added in v0.1.19
type NewChoice struct {
Kind string
ModuleID string
TaskID string
LessonID string
NotAdmitted bool
ReasonCode int
IssuedSkills []string
PackageDigest string
MapSkill string
AgeCategory string
Grade *int
PoolLimited bool
Mark Mark
EngineVersion string
LastSeq int64
Digests []string
EngineDigests []string
// AfterAttemptID and AfterLessonRunID name the close of an attempt or the end
// of a run that gave the choice as what comes next.
AfterAttemptID *string
AfterLessonRunID *string
}
NewChoice is an engine's choice as it is written (R06, R50; R107 spec): what it gives — a task, a lesson or nothing, with the outcome "not admitted" or none —, its reason code, the skills it handed out and the package it was made on, and the input a replay needs — the skill chosen on the skill map, the age category and the grade of the profile, whether the pool was limited to the tasks a tap checks, the versions, the release and the window, the number of the last evidence read, and the digests of the graphs —, with the close or the end of a run whose next it is, when it is one.
type NewRun ¶ added in v0.1.17
type NewRun struct {
LessonID string
ModuleID string
ModuleVersion string
PackageDigest string
ChoiceID string
}
NewRun is what a lesson run begins with: the lesson, its module and version, the package, and the engine's choice that opens it.
type OpenAttempt ¶ added in v0.1.15
OpenAttempt is a profile's open attempt, as the list of profiles names it: its ID, and its lesson run and segment when it is one of a run.
func RunAttempt ¶ added in v0.1.17
RunAttempt is the run's open attempt and the place of its segment, and whether it has one.
type OpenLessonRun ¶ added in v0.1.17
OpenLessonRun is a profile's open lesson run, as the list of profiles names it: its ID, the lesson's full ID and its package.
type Owed ¶ added in v0.1.18
type Owed struct {
ID string
PackageDigest string
ModuleID string
TaskID string
Instance *int
CloseReason string
WrongAnswers int
LastActionAt time.Time
StepTechniques bool
RequestedTechniques bool
ExplainedAgain int
SolutionSeenBefore bool
Answers [][]byte
}
Owed is a closed attempt whose evidence is not in the journal yet, with what its evidence is built of (R06, R10): what it was of, how it closed, its last action, the techniques given at a step and on request, how many times "explain differently" was asked for, whether the solution of its task reached the device before it began, and the answers of its submissions, in order. The leading question is not among them: its field comes with a later release of learner-model (Д17).
func OwedAttempts ¶ added in v0.1.18
func OwedAttempts(ctx context.Context, tx pgx.Tx, profileID string, digests []string) ([]Owed, error)
OwedAttempts is the profile's attempts that owe their evidence, on the packages digests names — those the image holds: one whose package left the image gives none (Д27) —, in the order they closed.
type Profile ¶ added in v0.1.5
type Profile struct {
ID string
Owner bool
Pseudonym string
Avatar string
AgeCategory string
Country string
VoicingEnabled bool
VoicingSpeed string
DefaultMode string
InterfaceLanguage *string
Grade *int16
AskBeforeShowing bool
// OpenAttempt is the profile's open attempt, which the view of the account
// alone reads: nil when it has none.
OpenAttempt *OpenAttempt
// OpenLessonRuns are the profile's open lesson runs, one at most for each
// lesson, which the view of the account alone reads.
OpenLessonRuns []OpenLessonRun
}
Profile is a profile's row, with the contract's codes as the schema keeps them.
func CreateChildProfile ¶ added in v0.1.7
func CreateChildProfile(ctx context.Context, tx pgx.Tx, accountID string, c Consent, p Profile) (Profile, error)
CreateChildProfile makes the profile of a confirmed consent, which ConsentFor held, of its category and country, binds the consent to it, and makes the row of its skill state. The date the age was given is the date the consent was asked for, by UTC.
func CreateOwnerProfile ¶ added in v0.1.7
func CreateOwnerProfile(ctx context.Context, tx pgx.Tx, accountID string, p Profile) (Profile, error)
CreateOwnerProfile makes the owner's profile in tx, of the category adult by the owner's statement, with its consent: confirmed now, given by that statement (R36; architecture 3.1), and the row of its skill state. The date the age was given is the date of the statement, and every date is by UTC, as TouchProfile writes it. The account has one owner's profile: a second is ErrProfileExists.
type ProfileRef ¶ added in v0.1.9
ProfileRef is a profile the daily job works on, with its account.
func IdleProfiles ¶ added in v0.1.9
func IdleProfiles(ctx context.Context, db Lister, before time.Time, after string, limit int) ([]ProfileRef, error)
IdleProfiles is up to limit profiles of accounts not marked, active last before before, whose ID comes after after, by ID: those the daily job deletes after 12 months without activity (П-9).
type Querier ¶ added in v0.1.4
type Querier interface {
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}
Querier is what a read runs on: a pool, a connection or a transaction.
type Record ¶ added in v0.1.18
type Record struct {
ID string
TaskID string
ModuleID string
ModuleVersion string
LessonID *string
CloseReason *string
WrongAnswers int
StartedAt time.Time
ClosedAt *time.Time
ChosenAt *time.Time
ReasonCode *int
}
Record is an attempt in the progress of a profile (contract, AttemptRecord): what it was of, the lesson of its run, how it closed, when it began and closed, and when the engine chose its task — or its run's lesson — and why: none for an attempt begun again, or by a choice written before the codes.
type Run ¶ added in v0.1.19
type Run struct {
LessonID string
ModuleID string
PackageDigest string
EndReason *string
EndedAt *time.Time
}
Run is a lesson run of the profile as the engine's input reads it: its lesson, its package, and how and when it ended, while it has.
type Rung ¶ added in v0.1.17
Rung is what an attempt keeps of one of its rungs (R47): its words, and, once "explain differently" was asked for on it, the words that came of it, which the learner reads from then on. The words are empty once the attempt has closed.
type SkillState ¶ added in v0.1.18
SkillState is a profile's row of the cache of the skill state: the state as learner-model's codec gives it, empty while it was never written, its mark, and the number of the last evidence it holds.
func HoldSkillState ¶ added in v0.1.18
HoldSkillState holds the profile's row of the cache FOR UPDATE in tx, so that the evidence of one profile is numbered and folded one piece after another (R06). The profile's own row is held FOR KEY SHARE first, as the rows of the journal that the caller then adds refer to it: a deletion of the profile, which takes it FOR UPDATE before its cascade reaches the cache, waits, rather than locking the two rows in the other order. A profile the image before this one made has no row of the cache, so the row is made first, empty, when it is not there (the 2026-11-10 amendment to R06); a profile gone is ErrNoProfile.
type Solution ¶ added in v0.1.19
Solution is when the solution of a task of a module last went to the profile's device: an attempt of it closed correct or with the solution shown (R82 spec).
type TxBeginner ¶ added in v0.1.5
TxBeginner is what a transaction with its options starts from: a pool, or a connection.
type View ¶ added in v0.1.5
type View struct {
// ID is the account's ID.
ID string
// PinSet says the PIN of the section for adults is set.
PinSet bool
// Profiles are the account's profiles: the owner's first, then by when they
// were created.
Profiles []Profile
// ChildConsents are the consents for a child that have no profile, by when
// they were asked for.
ChildConsents []ChildConsent
}
View is the account as GetAccount gives it (contract, Account): whether its PIN is set, its profiles with their open attempts, and its consents for a child with no profile yet.
func AccountView ¶ added in v0.1.5
AccountView reads the account in one snapshot, so that its profiles and its consents are of one moment: a device erases the profiles the list does not hold (contract, GetAccount). An account that is not there is ErrNoAccount, and one marked "deleting" ErrAccountDeleting.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package storetest runs the tests of api's database on a real PostgreSQL with no Docker, as the devcontainer and CI have none: embedded-postgres starts one server for a test binary, when its first test asks for a database, migrates a template database once, and gives each test a database of its own made from it, which is a copy and takes milliseconds (R29; amendment of 2026-11-02 to R05).
|
Package storetest runs the tests of api's database on a real PostgreSQL with no Docker, as the devcontainer and CI have none: embedded-postgres starts one server for a test binary, when its first test asks for a database, migrates a template database once, and gives each test a database of its own made from it, which is a copy and takes milliseconds (R29; amendment of 2026-11-02 to R05). |