Documentation
¶
Overview ¶
Package repo holds database queries.
Index ¶
- Constants
- Variables
- func FeedTokenForUser(ctx context.Context, exec Executor, userID string) (*model.UserFeedToken, error)
- func FeedTokenOwner(ctx context.Context, exec Executor, token string) (*model.User, error)
- func RegenerateFeedToken(ctx context.Context, exec Executor, userID string) (*model.UserFeedToken, error)
- type Executor
- type Hop
- type JobArgs
- type JobQueue
- type LockScope
- type Page
- type PostsPage
- type ProofreadRequestCount
- type ProofreadRequestFilter
- type Queries
- type Store
- func (s *Store) APIKeyForUser(ctx context.Context, userID string) (*model.UserAPIKey, error)
- func (s *Store) AddMediatorDecision(ctx context.Context, requestID, mediatorID string, ...) error
- func (s *Store) CommentByID(ctx context.Context, id string) (*model.PostComment, error)
- func (s *Store) CommentForMail(ctx context.Context, id string) (*model.PostComment, error)
- func (s *Store) CommentInPost(ctx context.Context, commentID, postID string) (*model.PostComment, error)
- func (s *Store) CommentParticipants(ctx context.Context, postID, authorID string) ([]*model.PostComment, error)
- func (s *Store) CommentedPostIDs(ctx context.Context, userID string) ([]string, error)
- func (s *Store) CommentsOfPost(ctx context.Context, postID string) ([]*model.PostComment, error)
- func (s *Store) CommentsOnPostsNotBy(ctx context.Context, postIDs []string, userID string, page Page) ([]*model.PostComment, error)
- func (s *Store) Connected(ctx context.Context, userID, otherID string) (bool, error)
- func (s *Store) ConnectedThroughOne(ctx context.Context, userID, otherID string) (bool, error)
- func (s *Store) ConnectedUserIDs(ctx context.Context, userID string) ([]string, error)
- func (s *Store) CountNewComment(ctx context.Context, postID string) error
- func (s *Store) CreateAPIKey(ctx context.Context, userID string) error
- func (s *Store) CreateConnection(ctx context.Context, user1ID, user2ID string) (*model.UserConnection, *model.UserConnection, error)
- func (s *Store) CreateGrant(ctx context.Context, whoID, allowsWhoID string) error
- func (s *Store) CreateMediaUpload(ctx context.Context, upload *model.MediaUpload) error
- func (s *Store) CreateMediationRequest(ctx context.Context, whoID, targetID, note string) error
- func (s *Store) CreateShare(ctx context.Context, postID string) error
- func (s *Store) DeleteConnectionsBetween(ctx context.Context, userID, otherID string) error
- func (s *Store) DeleteEmailSubscription(ctx context.Context, id string) error
- func (s *Store) DeleteLoginAttemptsExpiredBefore(ctx context.Context, t time.Time) (int64, error)
- func (s *Store) DeleteMediationRequestBetween(ctx context.Context, whoID, targetID string) error
- func (s *Store) DeleteOpenGrant(ctx context.Context, whoID, allowsWhoID string) error
- func (s *Store) DeletePendingEmailSubscriptionsSentBefore(ctx context.Context, t time.Time) (int64, error)
- func (s *Store) DeletePost(ctx context.Context, postID string) error
- func (s *Store) DeletePowChallengesBefore(ctx context.Context, t time.Time) error
- func (s *Store) DeleteProfileAbout(ctx context.Context, userID string) error
- func (s *Store) DeleteShares(ctx context.Context, postID string) error
- func (s *Store) DeleteStyleReviews(ctx context.Context, postID string) error
- func (s *Store) DeleteSubscriberIfEmpty(ctx context.Context, id string) error
- func (s *Store) DeleteSubscribersWithoutSubscriptions(ctx context.Context) (int64, error)
- func (s *Store) DeleteSubscription(ctx context.Context, userID, subscriptionID string) error
- func (s *Store) DeleteSubscriptionMailsBefore(ctx context.Context, t time.Time) (int64, error)
- func (s *Store) DeleteUnconfirmedUser(ctx context.Context, id string) (bool, error)
- func (s *Store) DismissFeedItem(ctx context.Context, item *model.UserFeedItem) error
- func (s *Store) DismissPrompt(ctx context.Context, recipientID, id string, at time.Time) error
- func (s *Store) DraftPosts(ctx context.Context, userID string) ([]*model.Post, error)
- func (s *Store) EmailSubscriptionByConfirmToken(ctx context.Context, token string) (*model.EmailSubscription, error)
- func (s *Store) EmailSubscriptionByID(ctx context.Context, id string) (*model.EmailSubscription, error)
- func (s *Store) EmailSubscriptionCount(ctx context.Context, authorID string, status model.SubscriptionStatus) (int, error)
- func (s *Store) EmailSubscriptionOf(ctx context.Context, subscriberID, authorID string) (*model.EmailSubscription, error)
- func (s *Store) EmailSubscriptionsOfAuthor(ctx context.Context, authorID string, status model.SubscriptionStatus) ([]*model.EmailSubscription, error)
- func (s *Store) EmailSubscriptionsOfSubscriber(ctx context.Context, subscriberID string, status model.SubscriptionStatus) ([]*model.EmailSubscription, error)
- func (s *Store) Enqueue(ctx context.Context, q JobQueue, args JobArgs) error
- func (s *Store) Exec() Executor
- func (s *Store) FeedByID(ctx context.Context, feedID string) (*model.RSSFeed, error)
- func (s *Store) FeedItemCount(ctx context.Context, feedID string) (int64, error)
- func (s *Store) FeedItemExists(ctx context.Context, feedID, urlID string) (bool, error)
- func (s *Store) FeedItemExistsForURL(ctx context.Context, feedID, rawURL string) (bool, error)
- func (s *Store) FeedSubscriptions(ctx context.Context, feedID string) ([]*model.UserFeedSubscription, error)
- func (s *Store) FeedTokenForUser(ctx context.Context, userID string) (*model.UserFeedToken, error)
- func (s *Store) FeedTokenOwner(ctx context.Context, token string) (*model.User, error)
- func (s *Store) FeedsToRefresh(ctx context.Context) ([]*model.RSSFeed, error)
- func (s *Store) GrantExists(ctx context.Context, whoID, allowsWhoID string) (bool, error)
- func (s *Store) InsertComment(ctx context.Context, comment *model.PostComment) error
- func (s *Store) InsertEmailSubscription(ctx context.Context, sub *model.EmailSubscription) error
- func (s *Store) InsertInvitation(ctx context.Context, inv *model.UserInvitation) error
- func (s *Store) InsertLoginAttempt(ctx context.Context, a *model.LoginAttempt) error
- func (s *Store) InsertPost(ctx context.Context, post *model.Post) error
- func (s *Store) InsertPrompt(ctx context.Context, prompt *model.PostPrompt) error
- func (s *Store) InsertProofreadRequest(ctx context.Context, r *model.ProofreadRequest) error
- func (s *Store) InsertSignupRequest(ctx context.Context, r *model.UserSignupRequest) error
- func (s *Store) InsertStyleReview(ctx context.Context, review *model.StyleReview) error
- func (s *Store) InsertSubscriber(ctx context.Context, sub *model.EmailSubscriber) error
- func (s *Store) InsertUser(ctx context.Context, u *model.User) error
- func (s *Store) InsertUserFeedItem(ctx context.Context, userID, rssItemID, urlID string) error
- func (s *Store) InvitationCount(ctx context.Context, userID string) (int64, error)
- func (s *Store) InvitationSentTo(ctx context.Context, email string) (bool, error)
- func (s *Store) LastImportedAt(ctx context.Context, feedIDs []string) (map[string]time.Time, error)
- func (s *Store) LastPromptBy(ctx context.Context, askerID string) (*model.PostPrompt, error)
- func (s *Store) LockFeed(ctx context.Context, feedID string) (*model.RSSFeed, error)
- func (s *Store) LockLoginAttempt(ctx context.Context, id string) (*model.LoginAttempt, error)
- func (s *Store) LockMailbox(ctx context.Context, scope LockScope, canonical string) error
- func (s *Store) LockOpenGrant(ctx context.Context, whoID, allowsWhoID string) (*model.WhitelistedConnection, error)
- func (s *Store) LockSubscriber(ctx context.Context, id string) (*model.EmailSubscriber, error)
- func (s *Store) LockUndecidedRequest(ctx context.Context, requestID, targetID string) (*model.UserConnectionMediationRequest, error)
- func (s *Store) LockUnusedInvitation(ctx context.Context, userID string) (*model.UserInvitation, error)
- func (s *Store) LockUser(ctx context.Context, scope LockScope, userID string) error
- func (s *Store) LogSubscriptionMail(ctx context.Context, row *model.SubscriptionMailLog) error
- func (s *Store) LoginCodesSince(ctx context.Context, userID string, since time.Time) (int64, error)
- func (s *Store) MailboxHasAccount(ctx context.Context, canonical string) (bool, error)
- func (s *Store) MarkPostSubscribersMailed(ctx context.Context, postID string, t time.Time) (bool, error)
- func (s *Store) MediationRequestBetween(ctx context.Context, whoID, targetID string) (*model.UserConnectionMediationRequest, error)
- func (s *Store) MediationRequestExists(ctx context.Context, whoID, targetID string) (bool, error)
- func (s *Store) OpenGrantExists(ctx context.Context, whoID, allowsWhoID string) (bool, error)
- func (s *Store) OpenInvitationByID(ctx context.Context, id string) (*model.UserInvitation, error)
- func (s *Store) OpenPromptsFor(ctx context.Context, recipientID string) ([]*model.PostPrompt, error)
- func (s *Store) OwnPost(ctx context.Context, postID, authorID string) (*model.Post, error)
- func (s *Store) OwnPostForUpdate(ctx context.Context, postID, authorID string, draftOnly bool) (*model.Post, error)
- func (s *Store) OwnPostsByIDs(ctx context.Context, authorID string, ids []string) ([]*model.Post, error)
- func (s *Store) PendingInvitationExists(ctx context.Context, email string) (bool, error)
- func (s *Store) PostByID(ctx context.Context, id string) (*model.Post, error)
- func (s *Store) PostForEdit(ctx context.Context, id string) (*model.Post, error)
- func (s *Store) PostToRead(ctx context.Context, id string) (*model.Post, error)
- func (s *Store) PostWithAuthorAndURL(ctx context.Context, id string) (*model.Post, error)
- func (s *Store) PostsByAuthor(ctx context.Context, page PostsPage) ([]*model.Post, error)
- func (s *Store) PostsForExport(ctx context.Context, authorID, postID string) ([]*model.Post, error)
- func (s *Store) PostsOfOrAmong(ctx context.Context, userID string, authorIDs, postIDs []string) ([]*model.Post, error)
- func (s *Store) ProfileAbout(ctx context.Context, userID string) (string, error)
- func (s *Store) PromptForPost(ctx context.Context, postID string) (*model.PostPrompt, error)
- func (s *Store) PromptForRecipient(ctx context.Context, recipientID, id string) (*model.PostPrompt, error)
- func (s *Store) ProofreadRequestsSince(ctx context.Context, f ProofreadRequestFilter) (ProofreadRequestCount, error)
- func (s *Store) PublishedPostsByProfile(ctx context.Context, visibility model.PostVisibility, ...) ([]*model.Post, error)
- func (s *Store) PublishedPostsOf(ctx context.Context, authorID string, visibilities []model.PostVisibility, ...) ([]*model.Post, error)
- func (s *Store) PublishedPostsOfUsers(ctx context.Context, allOf, someOf []string, ...) ([]*model.Post, error)
- func (s *Store) RecordSentEmail(ctx context.Context, email *model.SentEmail) (bool, error)
- func (s *Store) RecordTargetDecision(ctx context.Context, req *model.UserConnectionMediationRequest, ...) error
- func (s *Store) RegenerateFeedToken(ctx context.Context, userID string) (*model.UserFeedToken, error)
- func (s *Store) RegistrationOpen(ctx context.Context) (bool, error)
- func (s *Store) RequestsToDecide(ctx context.Context, targetID string) ([]*model.UserConnectionMediationRequest, error)
- func (s *Store) RequestsToMediate(ctx context.Context, userIDs []string, mediatorID string) ([]*model.UserConnectionMediationRequest, error)
- func (s *Store) SaveEmailSubscription(ctx context.Context, sub *model.EmailSubscription, columns ...string) error
- func (s *Store) SaveFeed(ctx context.Context, feed *model.RSSFeed) error
- func (s *Store) SaveInvitation(ctx context.Context, inv *model.UserInvitation) error
- func (s *Store) SaveLoginAttempt(ctx context.Context, a *model.LoginAttempt, columns ...string) error
- func (s *Store) SaveProfileAbout(ctx context.Context, userID, about string) error
- func (s *Store) SaveSignupRequest(ctx context.Context, r *model.UserSignupRequest) error
- func (s *Store) SaveUser(ctx context.Context, u *model.User, columns ...string) error
- func (s *Store) SaveUserStyle(ctx context.Context, userID, styles string) error
- func (s *Store) SentInvitations(ctx context.Context, userID string) ([]*model.UserInvitation, error)
- func (s *Store) SetOpenStyleNotesStatus(ctx context.Context, ids []string, status model.StyleNoteStatus) error
- func (s *Store) SetRegistrationOpen(ctx context.Context, open bool) error
- func (s *Store) SetStyleNoteStatus(ctx context.Context, id string, status model.StyleNoteStatus, reason string) error
- func (s *Store) ShareByID(ctx context.Context, id string) (*model.PostShare, error)
- func (s *Store) ShareOfPost(ctx context.Context, postID string) (*model.PostShare, error)
- func (s *Store) SignupRequestByID(ctx context.Context, id string) (*model.UserSignupRequest, error)
- func (s *Store) SignupRequestEmailExists(ctx context.Context, email string) (bool, error)
- func (s *Store) StoreURL(ctx context.Context, rawURL string) (*model.NormalizedURL, error)
- func (s *Store) StyleReviewNote(ctx context.Context, id string) (*model.StyleReviewNote, error)
- func (s *Store) StyleReviews(ctx context.Context, postID string) ([]*model.StyleReview, error)
- func (s *Store) Subscribe(ctx context.Context, userID, feedID string) error
- func (s *Store) SubscriberByEmail(ctx context.Context, email string) (*model.EmailSubscriber, error)
- func (s *Store) SubscriberByID(ctx context.Context, id string) (*model.EmailSubscriber, error)
- func (s *Store) SubscriberByManageToken(ctx context.Context, token string) (*model.EmailSubscriber, error)
- func (s *Store) SubscriptionMailsSince(ctx context.Context, since time.Time, kind model.SubscriptionMailKind, ...) (int, error)
- func (s *Store) SubscriptionMailsTo(ctx context.Context, canonical string, kind model.SubscriptionMailKind, ...) (int, error)
- func (s *Store) SubscriptionsOf(ctx context.Context, userID string) ([]*model.UserFeedSubscription, error)
- func (s *Store) TwoHops(ctx context.Context, userID string) ([]*Hop, error)
- func (s *Store) Tx(ctx context.Context, fn func(tx *Store) error) error
- func (s *Store) UnconfirmedUserIDsCreatedBefore(ctx context.Context, t time.Time) ([]string, error)
- func (s *Store) UndecidedRequestBetween(ctx context.Context, requestID string, userIDs []string) (*model.UserConnectionMediationRequest, error)
- func (s *Store) UndismissedFeedItems(ctx context.Context, userID string, page Page) ([]*model.UserFeedItem, error)
- func (s *Store) UnexpiredLoginAttempts(ctx context.Context, userID string, now time.Time) ([]*model.LoginAttempt, error)
- func (s *Store) UpdateCommentBody(ctx context.Context, comment *model.PostComment, body string) error
- func (s *Store) UpdatePost(ctx context.Context, post *model.Post) error
- func (s *Store) UpdatePrompt(ctx context.Context, prompt *model.PostPrompt) error
- func (s *Store) UploadsByName(ctx context.Context, userID string, names []string) ([]*model.MediaUpload, error)
- func (s *Store) UpsertFeed(ctx context.Context, normalizedURL string) (*model.RSSFeed, error)
- func (s *Store) UpsertFeedItem(ctx context.Context, item *model.RSSItem) (created bool, err error)
- func (s *Store) UseGrant(ctx context.Context, grant *model.WhitelistedConnection, connectionID string) error
- func (s *Store) UsePowChallenge(ctx context.Context, salt string, at time.Time) (bool, error)
- func (s *Store) UserByAPIKey(ctx context.Context, key string) (*model.User, error)
- func (s *Store) UserByEmail(ctx context.Context, email string) (*model.User, error)
- func (s *Store) UserByID(ctx context.Context, id string) (*model.User, error)
- func (s *Store) UserByUsername(ctx context.Context, username string) (*model.User, error)
- func (s *Store) UserEmailExists(ctx context.Context, email string) (bool, error)
- func (s *Store) UserFeedItemByID(ctx context.Context, userID, itemID string) (*model.UserFeedItem, error)
- func (s *Store) UserStyleByUsername(ctx context.Context, username string) (*model.UserStyle, error)
- func (s *Store) UserStyleForUser(ctx context.Context, userID string) (*model.UserStyle, error)
- func (s *Store) UsernameExists(ctx context.Context, username string) (bool, error)
- func (s *Store) UsersByIDs(ctx context.Context, ids []string) ([]*model.User, error)
- func (s *Store) UsersByIDsNewestFirst(ctx context.Context, ids []string) ([]*model.User, error)
- func (s *Store) WhitelistTarget(ctx context.Context, username string) (*model.User, error)
- func (s *Store) WhitelistedUsers(ctx context.Context, whoID string) ([]*model.User, error)
- func (s *Store) WrongLoginTriesSince(ctx context.Context, userID string, since time.Time) (int64, error)
Constants ¶
const ( KindComment = "comment" KindPost = "post" KindRSSItem = "rss" )
The kinds of the lists a feed merges. Kinds compare as strings and the merged order is descending, so on a tie it is rss, post, comment.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound replaces sql.ErrNoRows at the repository boundary.
Functions ¶
func FeedTokenForUser ¶
func FeedTokenOwner ¶
func RegenerateFeedToken ¶
Types ¶
type Executor ¶
type Executor interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
Executor runs queries: the database or a transaction. *sql.DB, *sql.Tx and *sql.DB all satisfy it.
type Hop ¶
Hop is one path of length two from a user: UserID is reached through ViaUserID. UserID may be the user themselves or a direct connection too.
type JobArgs ¶
type JobArgs interface {
Kind() string
}
JobArgs is a background job's arguments: a struct River stores as JSON, named by its Kind. It is river.JobArgs without the import; a job's insert options (max attempts, uniqueness) come from its InsertOpts method, as River reads them.
type JobQueue ¶
JobQueue inserts a job on the caller's executor, so the job exists only if the transaction commits. pkg/jobs implements it over River; fakequeue records the args for tests.
type LockScope ¶
type LockScope string
LockScope names what a per-user advisory lock guards, so that locks taken on the same user for different reasons never wait on each other.
const LockSubscribeMailbox LockScope = "subscribe_mailbox"
LockSubscribeMailbox guards a mailbox's subscriptions and the counts behind its mail limits.
type Page ¶
Page is one page of a list sorted newest first by a time, then by kind and ID, so that the order is total even across lists that are merged. A page holds what comes after the item (Before, BeforeKind, BeforeID); a zero Before is the first page. Limit caps the rows, 0 means no cap.
type PostsPage ¶
type PostsPage struct {
AuthorID string
// UpdatedSince keeps posts updated after it, when it is not zero.
UpdatedSince time.Time
// Cursor keeps posts with a smaller ID, when it is not empty.
Cursor string
Limit int
}
PostsPage is the query the API lists posts with.
type ProofreadRequestCount ¶
ProofreadRequestCount is how many calls matched, and when the oldest of them was made (zero when none did).
type ProofreadRequestFilter ¶
type ProofreadRequestFilter struct {
UserID string
Kind model.ProofreadKind
Status model.ProofreadStatus
Since time.Time
}
ProofreadRequestFilter narrows the calls ProofreadRequestsSince counts. An empty UserID or Kind matches every user or kind.
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
Queries builds bun queries that run on one executor.
func Query ¶
Query returns bun query builders that run on exec: the database or a transaction. The Store's methods use s.query(); test factories call it with the executor they are given.
func (Queries) NewInsert ¶
func (q Queries) NewInsert() *bun.InsertQuery
NewInsert starts an INSERT.
func (Queries) NewUpdate ¶
func (q Queries) NewUpdate() *bun.UpdateQuery
NewUpdate starts an UPDATE.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the entry point to every query. Methods live one file per aggregate (shares.go, posts.go, ...). They take no executor: the Store carries it, either the database or the transaction it was handed by Tx.
func ConnectPostgres ¶
ConnectPostgres opens a store on the database at dsn, for commands that run outside the web server. Close it with the returned function.
func Using ¶
Using returns a Store over an executor that already exists: a transaction opened elsewhere, or the executor a legacy function or a test factory holds. Tx on such a Store joins the executor instead of opening a transaction.
func (*Store) APIKeyForUser ¶
APIKeyForUser returns the user's API key, or nil when they have none.
func (*Store) AddMediatorDecision ¶
func (s *Store) AddMediatorDecision(ctx context.Context, requestID, mediatorID string, decision model.ConnectionMediationDecision, note string) error
AddMediatorDecision records the decision of a mediator on a request.
func (*Store) CommentByID ¶
CommentByID returns a comment, or ErrNotFound.
func (*Store) CommentForMail ¶
CommentForMail returns a comment with its author, its post and the post's author and linked URL loaded.
func (*Store) CommentInPost ¶
func (s *Store) CommentInPost(ctx context.Context, commentID, postID string) (*model.PostComment, error)
CommentInPost returns a comment of the given post, or ErrNotFound.
func (*Store) CommentParticipants ¶
func (s *Store) CommentParticipants(ctx context.Context, postID, authorID string) ([]*model.PostComment, error)
CommentParticipants returns one comment of every user, other than the post's author, who commented on the post, with the commenter loaded (comment.User). Only the comment's user_id is read.
func (*Store) CommentedPostIDs ¶
CommentedPostIDs returns the IDs of the posts userID has commented on.
func (*Store) CommentsOfPost ¶
CommentsOfPost returns a post's comments, oldest first, with their authors loaded.
func (*Store) CommentsOnPostsNotBy ¶
func (s *Store) CommentsOnPostsNotBy(ctx context.Context, postIDs []string, userID string, page Page) ([]*model.PostComment, error)
CommentsOnPostsNotBy returns a page of the comments on postIDs that someone other than userID left, newest first, with their authors loaded.
func (*Store) ConnectedThroughOne ¶
ConnectedThroughOne reports whether a path of length two joins the users.
func (*Store) ConnectedUserIDs ¶
ConnectedUserIDs returns the IDs of userID's direct connections.
func (*Store) CountNewComment ¶
CountNewComment adds one to the comment counter of a post.
func (*Store) CreateAPIKey ¶
CreateAPIKey gives the user an API key. A user has at most one, and there is no rotation: creating again keeps the existing key.
func (*Store) CreateConnection ¶
func (s *Store) CreateConnection(ctx context.Context, user1ID, user2ID string) (*model.UserConnection, *model.UserConnection, error)
CreateConnection stores a connection between two users. Since connections form an undirected graph, the ids go in in both combinations to simplify queries, at the cost of twice the rows. It is meant to run in a transaction. The (user1, user2) row is returned first.
func (*Store) CreateGrant ¶
CreateGrant lets allowsWho connect to who without mediation.
func (*Store) CreateMediaUpload ¶
CreateMediaUpload inserts a media upload record.
func (*Store) CreateMediationRequest ¶
CreateMediationRequest stores a request of who to target with an optional note.
func (*Store) CreateShare ¶
CreateShare gives a post its share link. A post has at most one, so creating it again keeps the existing link.
func (*Store) DeleteConnectionsBetween ¶
DeleteConnectionsBetween removes the connection of two users, in both directions, together with the whitelist grant and the mediation request (and its mediators) that led to it. Without a connection it does nothing. It is meant to run in a transaction.
func (*Store) DeleteEmailSubscription ¶
DeleteEmailSubscription deletes the subscription.
func (*Store) DeleteLoginAttemptsExpiredBefore ¶
DeleteLoginAttemptsExpiredBefore deletes the attempts that expired before t and returns how many there were.
func (*Store) DeleteMediationRequestBetween ¶
DeleteMediationRequestBetween removes the request of who to target with its mediators' decisions, locking them first. ErrNotFound when there is none.
func (*Store) DeleteOpenGrant ¶
DeleteOpenGrant withdraws the open grant of who for allowsWho.
func (*Store) DeletePendingEmailSubscriptionsSentBefore ¶
func (s *Store) DeletePendingEmailSubscriptionsSentBefore(ctx context.Context, t time.Time) (int64, error)
DeletePendingEmailSubscriptionsSentBefore deletes the pending subscriptions whose confirmation was mailed before t.
func (*Store) DeletePost ¶
DeletePost removes a post with everything that hangs off it: comments, stats, share link and the prompt it answered.
func (*Store) DeletePowChallengesBefore ¶
DeletePowChallengesBefore deletes the challenges used before t.
func (*Store) DeleteProfileAbout ¶
DeleteProfileAbout removes the user's "About" text; no text is fine.
func (*Store) DeleteShares ¶
DeleteShares removes a post's share link, if it has one.
func (*Store) DeleteStyleReviews ¶
DeleteStyleReviews removes every review of a post with its notes.
func (*Store) DeleteSubscriberIfEmpty ¶
DeleteSubscriberIfEmpty deletes the subscriber unless a subscription of theirs is left.
func (*Store) DeleteSubscribersWithoutSubscriptions ¶
DeleteSubscribersWithoutSubscriptions deletes every subscriber who has no subscription left.
func (*Store) DeleteSubscription ¶
DeleteSubscription removes a user's subscription. The feed row stays: the refresh schedule skips feeds without subscribers, and this avoids racing a user who adds the feed back.
func (*Store) DeleteSubscriptionMailsBefore ¶
DeleteSubscriptionMailsBefore deletes the mail log rows of every kind logged before t.
func (*Store) DeleteUnconfirmedUser ¶
DeleteUnconfirmedUser deletes the user unless they have confirmed their address meanwhile, and reports whether it did.
func (*Store) DismissFeedItem ¶
DismissFeedItem marks a feed item as dismissed.
func (*Store) DismissPrompt ¶
DismissPrompt marks a prompt addressed to the recipient as dismissed at the given time.
func (*Store) DraftPosts ¶
DraftPosts returns the unpublished posts of a user, the last edited first.
func (*Store) EmailSubscriptionByConfirmToken ¶
func (s *Store) EmailSubscriptionByConfirmToken(ctx context.Context, token string) (*model.EmailSubscription, error)
EmailSubscriptionByConfirmToken returns the subscription the confirmation token was mailed for, or ErrNotFound.
func (*Store) EmailSubscriptionByID ¶
func (s *Store) EmailSubscriptionByID(ctx context.Context, id string) (*model.EmailSubscription, error)
EmailSubscriptionByID returns the subscription, or ErrNotFound.
func (*Store) EmailSubscriptionCount ¶
func (s *Store) EmailSubscriptionCount(ctx context.Context, authorID string, status model.SubscriptionStatus) (int, error)
EmailSubscriptionCount is how many of the author's subscriptions are in the status given.
func (*Store) EmailSubscriptionOf ¶
func (s *Store) EmailSubscriptionOf(ctx context.Context, subscriberID, authorID string) (*model.EmailSubscription, error)
EmailSubscriptionOf returns the subscriber's subscription to the author, or nil when there is none.
func (*Store) EmailSubscriptionsOfAuthor ¶
func (s *Store) EmailSubscriptionsOfAuthor(ctx context.Context, authorID string, status model.SubscriptionStatus) ([]*model.EmailSubscription, error)
EmailSubscriptionsOfAuthor returns the author's subscriptions in the status given, each with its subscriber, the most recently confirmed first.
func (*Store) EmailSubscriptionsOfSubscriber ¶
func (s *Store) EmailSubscriptionsOfSubscriber(ctx context.Context, subscriberID string, status model.SubscriptionStatus) ([]*model.EmailSubscription, error)
EmailSubscriptionsOfSubscriber returns the subscriber's subscriptions in the status given, each with its author, by the author's username.
func (*Store) Enqueue ¶
Enqueue inserts a job on the store's executor: a service that enqueues inside Tx enqueues only if the transaction commits.
func (*Store) Exec ¶
Exec is the executor, for code that still takes one: forms' Save and the packages RS has not converted yet. Every call is a step RS removes.
func (*Store) FeedItemCount ¶
FeedItemCount is the number of items stored for a feed.
func (*Store) FeedItemExists ¶
FeedItemExists reports whether a feed has an item for a URL.
func (*Store) FeedItemExistsForURL ¶
FeedItemExistsForURL reports whether a feed has an item for a raw URL, normalized as StoreURL normalizes it. Unlike StoreURL it writes nothing: a URL never stored has no item.
func (*Store) FeedSubscriptions ¶
func (s *Store) FeedSubscriptions(ctx context.Context, feedID string) ([]*model.UserFeedSubscription, error)
FeedSubscriptions returns every subscription to a feed.
func (*Store) FeedTokenForUser ¶
FeedTokenForUser returns the user's feed token, or nil when they have none.
func (*Store) FeedTokenOwner ¶
FeedTokenOwner returns the user a private RSS feed token belongs to, or ErrNotFound when the token is unknown.
func (*Store) FeedsToRefresh ¶
FeedsToRefresh returns the feeds due for a fetch that have at least one subscriber.
func (*Store) GrantExists ¶
GrantExists reports whether who has a grant for allowsWho, open or used.
func (*Store) InsertComment ¶
InsertComment stores a new comment.
func (*Store) InsertEmailSubscription ¶
InsertEmailSubscription inserts a new subscription.
func (*Store) InsertInvitation ¶
InsertInvitation inserts a new invitation.
func (*Store) InsertLoginAttempt ¶
InsertLoginAttempt stores a new login attempt.
func (*Store) InsertPost ¶
InsertPost stores a new post.
func (*Store) InsertPrompt ¶
InsertPrompt stores a new prompt.
func (*Store) InsertProofreadRequest ¶
InsertProofreadRequest records one call to the model, giving it an id when it has none.
func (*Store) InsertSignupRequest ¶
InsertSignupRequest adds an email to the waiting list; an email that is there already keeps its row.
func (*Store) InsertStyleReview ¶
InsertStyleReview stores a review and its notes, giving each an id and pointing the notes at the review.
func (*Store) InsertSubscriber ¶
InsertSubscriber inserts a new subscriber.
func (*Store) InsertUser ¶
InsertUser inserts a new account.
func (*Store) InsertUserFeedItem ¶
InsertUserFeedItem shows a stored item to a user.
func (*Store) InvitationCount ¶
InvitationCount counts every invitation the user owns, sent or not.
func (*Store) InvitationSentTo ¶
InvitationSentTo reports whether any invitation went to the (normalized) email, accepted or not.
func (*Store) LastImportedAt ¶
LastImportedAt maps each feed to the time its newest item was stored. Feeds without items are missing from the map.
func (*Store) LastPromptBy ¶
LastPromptBy returns the newest prompt the user sent, or ErrNotFound.
func (*Store) LockFeed ¶
LockFeed loads a feed and locks its row until the transaction ends, waiting for a transaction that holds it. A missing feed is ErrNotFound.
func (*Store) LockLoginAttempt ¶
LockLoginAttempt returns the attempt locked for update, or ErrNotFound.
func (*Store) LockMailbox ¶
LockMailbox is LockUser for a mailbox (see pgsession.CanonicalEmail), so every spelling of an address takes the same lock.
func (*Store) LockOpenGrant ¶
func (s *Store) LockOpenGrant(ctx context.Context, whoID, allowsWhoID string) (*model.WhitelistedConnection, error)
LockOpenGrant returns the open grant of who for allowsWho and locks it until the transaction ends. ErrNotFound when there is none.
func (*Store) LockSubscriber ¶
LockSubscriber reads the subscriber and locks its row until the transaction ends, or returns ErrNotFound. Every change to a subscription takes this lock first.
func (*Store) LockUndecidedRequest ¶
func (s *Store) LockUndecidedRequest(ctx context.Context, requestID, targetID string) (*model.UserConnectionMediationRequest, error)
LockUndecidedRequest returns request requestID addressed to targetID, if the target has not decided yet, and locks it until the transaction ends. ErrNotFound otherwise.
func (*Store) LockUnusedInvitation ¶
func (s *Store) LockUnusedInvitation(ctx context.Context, userID string) (*model.UserInvitation, error)
LockUnusedInvitation returns and locks one of the user's invitations that has no email yet, skipping rows locked by others, or ErrNotFound.
func (*Store) LockUser ¶
LockUser takes the transaction-level advisory lock of scope on the user, waiting while another transaction holds it; commit or rollback releases it. Outside a transaction it fails, since the lock would be gone before the next statement.
func (*Store) LogSubscriptionMail ¶
LogSubscriptionMail records a confirmation or manage-link mail, or a DNS lookup of a subscribing address's domain.
func (*Store) LoginCodesSince ¶
LoginCodesSince counts the user's attempts created after since that were issued a code.
func (*Store) MailboxHasAccount ¶
MailboxHasAccount reports whether an account uses an address that delivers to the mailbox canonical (see pgsession.CanonicalEmail).
func (*Store) MarkPostSubscribersMailed ¶
func (s *Store) MarkPostSubscribersMailed(ctx context.Context, postID string, t time.Time) (bool, error)
MarkPostSubscribersMailed records that the post's subscribers were mailed at t, and reports false when they already were.
func (*Store) MediationRequestBetween ¶
func (s *Store) MediationRequestBetween(ctx context.Context, whoID, targetID string) (*model.UserConnectionMediationRequest, error)
MediationRequestBetween returns the request of who to target. ErrNotFound when there is none.
func (*Store) MediationRequestExists ¶
MediationRequestExists reports whether who has a request to target.
func (*Store) OpenGrantExists ¶
OpenGrantExists reports whether who has an open grant for allowsWho.
func (*Store) OpenInvitationByID ¶
OpenInvitationByID returns an invitation nobody has accepted yet, with its inviter loaded (invite.User), or ErrNotFound.
func (*Store) OpenPromptsFor ¶
func (s *Store) OpenPromptsFor(ctx context.Context, recipientID string) ([]*model.PostPrompt, error)
OpenPromptsFor returns the prompts sent to recipientID that they haven't dismissed, newest first, with the asker and the answer post loaded.
func (*Store) OwnPostForUpdate ¶
func (s *Store) OwnPostForUpdate(ctx context.Context, postID, authorID string, draftOnly bool) (*model.Post, error)
OwnPostForUpdate locks and returns a post of the given author. With draftOnly a published post is not found.
func (*Store) OwnPostsByIDs ¶
func (s *Store) OwnPostsByIDs(ctx context.Context, authorID string, ids []string) ([]*model.Post, error)
OwnPostsByIDs returns those of the given posts that belong to the author.
func (*Store) PendingInvitationExists ¶
PendingInvitationExists reports whether an invitation to the (normalized) email has been sent and not yet used to create an account.
func (*Store) PostForEdit ¶
PostForEdit returns a post with its author, stats and linked URL loaded (post.User, post.PostStat, post.URL).
func (*Store) PostToRead ¶
PostToRead returns a post, draft or published, with its author, stats and linked URL loaded (post.User, post.PostStat, post.URL).
func (*Store) PostWithAuthorAndURL ¶
PostWithAuthorAndURL returns a post with its author and linked URL loaded (post.User, post.URL).
func (*Store) PostsByAuthor ¶
PostsByAuthor returns an author's posts, newest ID first.
func (*Store) PostsForExport ¶
PostsForExport returns an author's posts with their linked URL loaded. With postID only that post is returned.
func (*Store) PostsOfOrAmong ¶
func (s *Store) PostsOfOrAmong(ctx context.Context, userID string, authorIDs, postIDs []string) ([]*model.Post, error)
PostsOfOrAmong returns the posts, drafts included, written by userID, and the published ones written by one of authorIDs whose ID is in postIDs, with their authors loaded.
func (*Store) ProfileAbout ¶
ProfileAbout returns the user's "About" text, or "" when there is none.
func (*Store) PromptForPost ¶
PromptForPost returns the prompt a post answers, with the asker loaded.
func (*Store) PromptForRecipient ¶
func (s *Store) PromptForRecipient(ctx context.Context, recipientID, id string) (*model.PostPrompt, error)
PromptForRecipient returns a prompt addressed to the recipient, with the asker loaded (prompt.Asker).
func (*Store) ProofreadRequestsSince ¶
func (s *Store) ProofreadRequestsSince(ctx context.Context, f ProofreadRequestFilter) (ProofreadRequestCount, error)
ProofreadRequestsSince counts the calls with the filter's status made at or after its Since.
func (*Store) PublishedPostsByProfile ¶
func (s *Store) PublishedPostsByProfile(ctx context.Context, visibility model.PostVisibility, profiles []model.ProfileVisibility, page Page) ([]*model.Post, error)
PublishedPostsByProfile returns a page, newest first, of the published posts with the given visibility whose authors have one of the profile visibilities given. Author, stats and linked URL are loaded.
func (*Store) PublishedPostsOf ¶
func (s *Store) PublishedPostsOf(ctx context.Context, authorID string, visibilities []model.PostVisibility, withStats bool, page Page) ([]*model.Post, error)
PublishedPostsOf returns a page of the author's published posts, newest first, with the author and linked URL loaded. visibilities limits the posts to those visibilities; nil means any. withStats loads post.PostStat too.
func (*Store) PublishedPostsOfUsers ¶
func (s *Store) PublishedPostsOfUsers(ctx context.Context, allOf, someOf []string, visibilities []model.PostVisibility, page Page) ([]*model.Post, error)
PublishedPostsOfUsers returns a page, newest first, of the published posts of the users in allOf, and those of the users in someOf that have one of the visibilities given. Author, stats and linked URL are loaded.
func (*Store) RecordSentEmail ¶
RecordSentEmail inserts the record of a mail about to be sent. It reports false, inserting nothing, when a mail of the same (email_type, unique_id) is already recorded: that mail was sent and this one is a repeat.
func (*Store) RecordTargetDecision ¶
func (s *Store) RecordTargetDecision(ctx context.Context, req *model.UserConnectionMediationRequest, decision model.ConnectionRequestDecision, connectionID, note string) error
RecordTargetDecision stores the decision of the request's target. A connectionID (empty for none) links the connection an approval created.
func (*Store) RegenerateFeedToken ¶
func (s *Store) RegenerateFeedToken(ctx context.Context, userID string) (*model.UserFeedToken, error)
RegenerateFeedToken creates the user's feed token or replaces the existing one, which stops working at once.
func (*Store) RegistrationOpen ¶
RegistrationOpen reports the system setting that lets anybody sign up.
func (*Store) RequestsToDecide ¶
func (s *Store) RequestsToDecide(ctx context.Context, targetID string) ([]*model.UserConnectionMediationRequest, error)
RequestsToDecide returns the undecided requests addressed to targetID that at least one mediator signed, with the requester and the signing mediators loaded.
func (*Store) RequestsToMediate ¶
func (s *Store) RequestsToMediate(ctx context.Context, userIDs []string, mediatorID string) ([]*model.UserConnectionMediationRequest, error)
RequestsToMediate returns the undecided requests between users of userIDs that mediatorID has not answered yet, with both sides loaded.
func (*Store) SaveEmailSubscription ¶
func (s *Store) SaveEmailSubscription(ctx context.Context, sub *model.EmailSubscription, columns ...string) error
SaveEmailSubscription writes the named columns of sub.
func (*Store) SaveInvitation ¶
SaveInvitation writes every column of the invitation.
func (*Store) SaveLoginAttempt ¶
func (s *Store) SaveLoginAttempt(ctx context.Context, a *model.LoginAttempt, columns ...string) error
SaveLoginAttempt writes the given columns of the attempt (all when none).
func (*Store) SaveProfileAbout ¶
SaveProfileAbout creates the user's "About" text or replaces it.
func (*Store) SaveSignupRequest ¶
SaveSignupRequest writes every column of the waiting list entry.
func (*Store) SaveUserStyle ¶
SaveUserStyle creates the user's custom CSS or replaces it.
func (*Store) SentInvitations ¶
func (s *Store) SentInvitations(ctx context.Context, userID string) ([]*model.UserInvitation, error)
SentInvitations returns the user's invitations that went to an email.
func (*Store) SetOpenStyleNotesStatus ¶
func (s *Store) SetOpenStyleNotesStatus(ctx context.Context, ids []string, status model.StyleNoteStatus) error
SetOpenStyleNotesStatus gives the notes among ids that are still open the status; notes the author has settled meanwhile keep theirs.
func (*Store) SetRegistrationOpen ¶
SetRegistrationOpen flips the system setting that lets anybody sign up.
func (*Store) SetStyleNoteStatus ¶
func (s *Store) SetStyleNoteStatus(ctx context.Context, id string, status model.StyleNoteStatus, reason string) error
SetStyleNoteStatus sets a note's status and keep reason.
func (*Store) ShareByID ¶
ShareByID returns a share with its post and the post's author loaded (share.Post, share.Post.User).
func (*Store) ShareOfPost ¶
ShareOfPost returns a post's share link, or nil when it has none.
func (*Store) SignupRequestByID ¶
SignupRequestByID returns a waiting list entry, or ErrNotFound.
func (*Store) SignupRequestEmailExists ¶
SignupRequestEmailExists reports whether the (normalized) email waits in the list.
func (*Store) StoreURL ¶
StoreURL normalizes the given URL and stores it in the normalized_urls table, keeping the existing row when the URL is known already.
func (*Store) StyleReviewNote ¶
StyleReviewNote returns a note with its review loaded (note.Review).
func (*Store) StyleReviews ¶
StyleReviews returns a post's reviews, newest first, each with its notes in their order.
func (*Store) SubscriberByEmail ¶
func (s *Store) SubscriberByEmail(ctx context.Context, email string) (*model.EmailSubscriber, error)
SubscriberByEmail returns the subscriber whose stored address is email, or ErrNotFound.
func (*Store) SubscriberByID ¶
SubscriberByID returns the subscriber, or ErrNotFound.
func (*Store) SubscriberByManageToken ¶
func (s *Store) SubscriberByManageToken(ctx context.Context, token string) (*model.EmailSubscriber, error)
SubscriberByManageToken returns the subscriber the manage token belongs to, or ErrNotFound.
func (*Store) SubscriptionMailsSince ¶
func (s *Store) SubscriptionMailsSince(ctx context.Context, since time.Time, kind model.SubscriptionMailKind, more ...model.SubscriptionMailKind) (int, error)
SubscriptionMailsSince counts the rows of kind, or of any of more, logged for anybody since t.
func (*Store) SubscriptionMailsTo ¶
func (s *Store) SubscriptionMailsTo(ctx context.Context, canonical string, kind model.SubscriptionMailKind, since time.Time) (int, error)
SubscriptionMailsTo counts the mails of kind sent to the mailbox canonical since t.
func (*Store) SubscriptionsOf ¶
func (s *Store) SubscriptionsOf(ctx context.Context, userID string) ([]*model.UserFeedSubscription, error)
SubscriptionsOf returns a user's subscriptions oldest first, with the feed loaded (sub.Feed).
func (*Store) Tx ¶
Tx runs fn in a transaction and commits when fn returns nil. Inside a transaction, Tx joins it, so a service method that opens one may call another that does. Repositories never call Tx; services do.
func (*Store) UnconfirmedUserIDsCreatedBefore ¶
UnconfirmedUserIDsCreatedBefore returns the ids of the users who never confirmed their address, were created before t and hold no invitations.
func (*Store) UndecidedRequestBetween ¶
func (s *Store) UndecidedRequestBetween(ctx context.Context, requestID string, userIDs []string) (*model.UserConnectionMediationRequest, error)
UndecidedRequestBetween returns request requestID when both its sides are among userIDs and the target has not decided yet. ErrNotFound otherwise.
func (*Store) UndismissedFeedItems ¶
func (s *Store) UndismissedFeedItems(ctx context.Context, userID string, page Page) ([]*model.UserFeedItem, error)
UndismissedFeedItems returns a page of a user's feed items that are not dismissed, newest addition first, with the item, its feed and its URL loaded.
func (*Store) UnexpiredLoginAttempts ¶
func (s *Store) UnexpiredLoginAttempts(ctx context.Context, userID string, now time.Time) ([]*model.LoginAttempt, error)
UnexpiredLoginAttempts returns the user's attempts that expire after now, newest first; the service decides which of them can still log in.
func (*Store) UpdateCommentBody ¶
func (s *Store) UpdateCommentBody(ctx context.Context, comment *model.PostComment, body string) error
UpdateCommentBody stores a new body of a comment and marks it as edited.
func (*Store) UpdatePost ¶
UpdatePost writes every column of an existing post.
func (*Store) UpdatePrompt ¶
UpdatePrompt writes every column of an existing prompt.
func (*Store) UploadsByName ¶
func (s *Store) UploadsByName(ctx context.Context, userID string, names []string) ([]*model.MediaUpload, error)
UploadsByName returns the user's uploads among the given file names.
func (*Store) UpsertFeed ¶
UpsertFeed returns the feed with this (already normalized) URL, creating it if nobody subscribed to it yet.
func (*Store) UpsertFeedItem ¶
UpsertFeedItem stores an item. If the feed already has one for the URL, the stored one is kept and created is false.
func (*Store) UseGrant ¶
func (s *Store) UseGrant(ctx context.Context, grant *model.WhitelistedConnection, connectionID string) error
UseGrant marks a grant as used by the connection.
func (*Store) UsePowChallenge ¶
UsePowChallenge records the salt of a proof-of-work challenge as used and reports whether it was new; false means it was answered before.
func (*Store) UserByAPIKey ¶
UserByAPIKey returns the user an API key belongs to, or ErrNotFound.
func (*Store) UserByEmail ¶
UserByEmail returns the user whose stored email is email, or ErrNotFound.
func (*Store) UserByUsername ¶
UserByUsername returns the user with that username.
func (*Store) UserEmailExists ¶
UserEmailExists reports whether an account uses the (normalized) email.
func (*Store) UserFeedItemByID ¶
func (s *Store) UserFeedItemByID(ctx context.Context, userID, itemID string) (*model.UserFeedItem, error)
UserFeedItemByID returns a user's feed item, or ErrNotFound if the user has no such item.
func (*Store) UserStyleByUsername ¶
UserStyleByUsername returns the custom CSS row of the user with the username, or nil when the user or the row does not exist.
func (*Store) UserStyleForUser ¶
UserStyleForUser returns the user's custom CSS row, or nil when they have none.
func (*Store) UsernameExists ¶
UsernameExists reports whether an account has the username.
func (*Store) UsersByIDs ¶
UsersByIDs returns the users with those IDs, in no particular order.
func (*Store) UsersByIDsNewestFirst ¶
UsersByIDsNewestFirst returns the users with those IDs, the most recently signed up first.
func (*Store) WhitelistTarget ¶
WhitelistTarget finds the user a whitelist grant is about, by username.
func (*Store) WhitelistedUsers ¶
WhitelistedUsers returns the users whoID has an open grant for.