repo

package
v0.0.0-...-f964ac6 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package repo holds database queries.

Index

Constants

View Source
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

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound replaces sql.ErrNoRows at the repository boundary.

Functions

func FeedTokenForUser

func FeedTokenForUser(ctx context.Context, exec Executor, userID string) (*model.UserFeedToken, error)

func FeedTokenOwner

func FeedTokenOwner(ctx context.Context, exec Executor, token string) (*model.User, error)

func RegenerateFeedToken

func RegenerateFeedToken(ctx context.Context, exec Executor, userID string) (*model.UserFeedToken, error)

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

type Hop struct {
	UserID    string `bun:"user_id"`
	ViaUserID string `bun:"via_user_id"`
}

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

type JobQueue interface {
	Insert(ctx context.Context, exec Executor, args JobArgs) error
}

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 (
	// LockLoginCodes guards the counts behind a user's login code limits.
	LockLoginCodes LockScope = "login_codes"
	// LockSignupMailbox guards the check that a mailbox has no account yet.
	LockSignupMailbox LockScope = "signup_mailbox"
)
const LockSubscribeMailbox LockScope = "subscribe_mailbox"

LockSubscribeMailbox guards a mailbox's subscriptions and the counts behind its mail limits.

type Page

type Page struct {
	Before     time.Time
	BeforeKind string
	BeforeID   string
	Limit      int
}

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

type ProofreadRequestCount struct {
	Count  int       `bun:"count"`
	Oldest time.Time `bun:"oldest"`
}

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

func Query(exec bun.IConn) Queries

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) NewDelete

func (q Queries) NewDelete() *bun.DeleteQuery

NewDelete starts a DELETE.

func (Queries) NewInsert

func (q Queries) NewInsert() *bun.InsertQuery

NewInsert starts an INSERT.

func (Queries) NewRaw

func (q Queries) NewRaw(query string, args ...any) *bun.RawQuery

NewRaw runs hand-written SQL, with bun's ? placeholders.

func (Queries) NewSelect

func (q Queries) NewSelect() *bun.SelectQuery

NewSelect starts a SELECT.

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

func ConnectPostgres(dsn string) (*Store, func() error, error)

ConnectPostgres opens a store on the database at dsn, for commands that run outside the web server. Close it with the returned function.

func New

func New(db *sql.DB) *Store

New returns a Store over db.

func Using

func Using(exec Executor) *Store

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

func (s *Store) APIKeyForUser(ctx context.Context, userID string) (*model.UserAPIKey, error)

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

func (s *Store) CommentByID(ctx context.Context, id string) (*model.PostComment, error)

CommentByID returns a comment, or ErrNotFound.

func (*Store) CommentForMail

func (s *Store) CommentForMail(ctx context.Context, id string) (*model.PostComment, error)

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

func (s *Store) CommentedPostIDs(ctx context.Context, userID string) ([]string, error)

CommentedPostIDs returns the IDs of the posts userID has commented on.

func (*Store) CommentsOfPost

func (s *Store) CommentsOfPost(ctx context.Context, postID string) ([]*model.PostComment, error)

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) Connected

func (s *Store) Connected(ctx context.Context, userID, otherID string) (bool, error)

Connected reports whether two users are directly connected.

func (*Store) ConnectedThroughOne

func (s *Store) ConnectedThroughOne(ctx context.Context, userID, otherID string) (bool, error)

ConnectedThroughOne reports whether a path of length two joins the users.

func (*Store) ConnectedUserIDs

func (s *Store) ConnectedUserIDs(ctx context.Context, userID string) ([]string, error)

ConnectedUserIDs returns the IDs of userID's direct connections.

func (*Store) CountNewComment

func (s *Store) CountNewComment(ctx context.Context, postID string) error

CountNewComment adds one to the comment counter of a post.

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(ctx context.Context, userID string) error

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

func (s *Store) CreateGrant(ctx context.Context, whoID, allowsWhoID string) error

CreateGrant lets allowsWho connect to who without mediation.

func (*Store) CreateMediaUpload

func (s *Store) CreateMediaUpload(ctx context.Context, upload *model.MediaUpload) error

CreateMediaUpload inserts a media upload record.

func (*Store) CreateMediationRequest

func (s *Store) CreateMediationRequest(ctx context.Context, whoID, targetID, note string) error

CreateMediationRequest stores a request of who to target with an optional note.

func (*Store) CreateShare

func (s *Store) CreateShare(ctx context.Context, postID string) error

CreateShare gives a post its share link. A post has at most one, so creating it again keeps the existing link.

func (*Store) DeleteConnectionsBetween

func (s *Store) DeleteConnectionsBetween(ctx context.Context, userID, otherID string) error

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

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

DeleteEmailSubscription deletes the subscription.

func (*Store) DeleteLoginAttemptsExpiredBefore

func (s *Store) DeleteLoginAttemptsExpiredBefore(ctx context.Context, t time.Time) (int64, error)

DeleteLoginAttemptsExpiredBefore deletes the attempts that expired before t and returns how many there were.

func (*Store) DeleteMediationRequestBetween

func (s *Store) DeleteMediationRequestBetween(ctx context.Context, whoID, targetID string) error

DeleteMediationRequestBetween removes the request of who to target with its mediators' decisions, locking them first. ErrNotFound when there is none.

func (*Store) DeleteOpenGrant

func (s *Store) DeleteOpenGrant(ctx context.Context, whoID, allowsWhoID string) error

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

func (s *Store) DeletePost(ctx context.Context, postID string) error

DeletePost removes a post with everything that hangs off it: comments, stats, share link and the prompt it answered.

func (*Store) DeletePowChallengesBefore

func (s *Store) DeletePowChallengesBefore(ctx context.Context, t time.Time) error

DeletePowChallengesBefore deletes the challenges used before t.

func (*Store) DeleteProfileAbout

func (s *Store) DeleteProfileAbout(ctx context.Context, userID string) error

DeleteProfileAbout removes the user's "About" text; no text is fine.

func (*Store) DeleteShares

func (s *Store) DeleteShares(ctx context.Context, postID string) error

DeleteShares removes a post's share link, if it has one.

func (*Store) DeleteStyleReviews

func (s *Store) DeleteStyleReviews(ctx context.Context, postID string) error

DeleteStyleReviews removes every review of a post with its notes.

func (*Store) DeleteSubscriberIfEmpty

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

DeleteSubscriberIfEmpty deletes the subscriber unless a subscription of theirs is left.

func (*Store) DeleteSubscribersWithoutSubscriptions

func (s *Store) DeleteSubscribersWithoutSubscriptions(ctx context.Context) (int64, error)

DeleteSubscribersWithoutSubscriptions deletes every subscriber who has no subscription left.

func (*Store) DeleteSubscription

func (s *Store) DeleteSubscription(ctx context.Context, userID, subscriptionID string) error

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

func (s *Store) DeleteSubscriptionMailsBefore(ctx context.Context, t time.Time) (int64, error)

DeleteSubscriptionMailsBefore deletes the mail log rows of every kind logged before t.

func (*Store) DeleteUnconfirmedUser

func (s *Store) DeleteUnconfirmedUser(ctx context.Context, id string) (bool, error)

DeleteUnconfirmedUser deletes the user unless they have confirmed their address meanwhile, and reports whether it did.

func (*Store) DismissFeedItem

func (s *Store) DismissFeedItem(ctx context.Context, item *model.UserFeedItem) error

DismissFeedItem marks a feed item as dismissed.

func (*Store) DismissPrompt

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

DismissPrompt marks a prompt addressed to the recipient as dismissed at the given time.

func (*Store) DraftPosts

func (s *Store) DraftPosts(ctx context.Context, userID string) ([]*model.Post, error)

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

func (s *Store) Enqueue(ctx context.Context, q JobQueue, args JobArgs) error

Enqueue inserts a job on the store's executor: a service that enqueues inside Tx enqueues only if the transaction commits.

func (*Store) Exec

func (s *Store) Exec() Executor

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) FeedByID

func (s *Store) FeedByID(ctx context.Context, feedID string) (*model.RSSFeed, error)

FeedByID loads a feed, or returns ErrNotFound.

func (*Store) FeedItemCount

func (s *Store) FeedItemCount(ctx context.Context, feedID string) (int64, error)

FeedItemCount is the number of items stored for a feed.

func (*Store) FeedItemExists

func (s *Store) FeedItemExists(ctx context.Context, feedID, urlID string) (bool, error)

FeedItemExists reports whether a feed has an item for a URL.

func (*Store) FeedItemExistsForURL

func (s *Store) FeedItemExistsForURL(ctx context.Context, feedID, rawURL string) (bool, error)

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

func (s *Store) FeedTokenForUser(ctx context.Context, userID string) (*model.UserFeedToken, error)

FeedTokenForUser returns the user's feed token, or nil when they have none.

func (*Store) FeedTokenOwner

func (s *Store) FeedTokenOwner(ctx context.Context, token string) (*model.User, error)

FeedTokenOwner returns the user a private RSS feed token belongs to, or ErrNotFound when the token is unknown.

func (*Store) FeedsToRefresh

func (s *Store) FeedsToRefresh(ctx context.Context) ([]*model.RSSFeed, error)

FeedsToRefresh returns the feeds due for a fetch that have at least one subscriber.

func (*Store) GrantExists

func (s *Store) GrantExists(ctx context.Context, whoID, allowsWhoID string) (bool, error)

GrantExists reports whether who has a grant for allowsWho, open or used.

func (*Store) InsertComment

func (s *Store) InsertComment(ctx context.Context, comment *model.PostComment) error

InsertComment stores a new comment.

func (*Store) InsertEmailSubscription

func (s *Store) InsertEmailSubscription(ctx context.Context, sub *model.EmailSubscription) error

InsertEmailSubscription inserts a new subscription.

func (*Store) InsertInvitation

func (s *Store) InsertInvitation(ctx context.Context, inv *model.UserInvitation) error

InsertInvitation inserts a new invitation.

func (*Store) InsertLoginAttempt

func (s *Store) InsertLoginAttempt(ctx context.Context, a *model.LoginAttempt) error

InsertLoginAttempt stores a new login attempt.

func (*Store) InsertPost

func (s *Store) InsertPost(ctx context.Context, post *model.Post) error

InsertPost stores a new post.

func (*Store) InsertPrompt

func (s *Store) InsertPrompt(ctx context.Context, prompt *model.PostPrompt) error

InsertPrompt stores a new prompt.

func (*Store) InsertProofreadRequest

func (s *Store) InsertProofreadRequest(ctx context.Context, r *model.ProofreadRequest) error

InsertProofreadRequest records one call to the model, giving it an id when it has none.

func (*Store) InsertSignupRequest

func (s *Store) InsertSignupRequest(ctx context.Context, r *model.UserSignupRequest) error

InsertSignupRequest adds an email to the waiting list; an email that is there already keeps its row.

func (*Store) InsertStyleReview

func (s *Store) InsertStyleReview(ctx context.Context, review *model.StyleReview) error

InsertStyleReview stores a review and its notes, giving each an id and pointing the notes at the review.

func (*Store) InsertSubscriber

func (s *Store) InsertSubscriber(ctx context.Context, sub *model.EmailSubscriber) error

InsertSubscriber inserts a new subscriber.

func (*Store) InsertUser

func (s *Store) InsertUser(ctx context.Context, u *model.User) error

InsertUser inserts a new account.

func (*Store) InsertUserFeedItem

func (s *Store) InsertUserFeedItem(ctx context.Context, userID, rssItemID, urlID string) error

InsertUserFeedItem shows a stored item to a user.

func (*Store) InvitationCount

func (s *Store) InvitationCount(ctx context.Context, userID string) (int64, error)

InvitationCount counts every invitation the user owns, sent or not.

func (*Store) InvitationSentTo

func (s *Store) InvitationSentTo(ctx context.Context, email string) (bool, error)

InvitationSentTo reports whether any invitation went to the (normalized) email, accepted or not.

func (*Store) LastImportedAt

func (s *Store) LastImportedAt(ctx context.Context, feedIDs []string) (map[string]time.Time, error)

LastImportedAt maps each feed to the time its newest item was stored. Feeds without items are missing from the map.

func (*Store) LastPromptBy

func (s *Store) LastPromptBy(ctx context.Context, askerID string) (*model.PostPrompt, error)

LastPromptBy returns the newest prompt the user sent, or ErrNotFound.

func (*Store) LockFeed

func (s *Store) LockFeed(ctx context.Context, feedID string) (*model.RSSFeed, error)

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

func (s *Store) LockLoginAttempt(ctx context.Context, id string) (*model.LoginAttempt, error)

LockLoginAttempt returns the attempt locked for update, or ErrNotFound.

func (*Store) LockMailbox

func (s *Store) LockMailbox(ctx context.Context, scope LockScope, canonical string) error

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

func (s *Store) LockSubscriber(ctx context.Context, id string) (*model.EmailSubscriber, error)

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

func (s *Store) LockUser(ctx context.Context, scope LockScope, userID string) error

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

func (s *Store) LogSubscriptionMail(ctx context.Context, row *model.SubscriptionMailLog) error

LogSubscriptionMail records a confirmation or manage-link mail, or a DNS lookup of a subscribing address's domain.

func (*Store) LoginCodesSince

func (s *Store) LoginCodesSince(ctx context.Context, userID string, since time.Time) (int64, error)

LoginCodesSince counts the user's attempts created after since that were issued a code.

func (*Store) MailboxHasAccount

func (s *Store) MailboxHasAccount(ctx context.Context, canonical string) (bool, error)

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

func (s *Store) MediationRequestExists(ctx context.Context, whoID, targetID string) (bool, error)

MediationRequestExists reports whether who has a request to target.

func (*Store) OpenGrantExists

func (s *Store) OpenGrantExists(ctx context.Context, whoID, allowsWhoID string) (bool, error)

OpenGrantExists reports whether who has an open grant for allowsWho.

func (*Store) OpenInvitationByID

func (s *Store) OpenInvitationByID(ctx context.Context, id string) (*model.UserInvitation, error)

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) OwnPost

func (s *Store) OwnPost(ctx context.Context, postID, authorID string) (*model.Post, error)

OwnPost returns a post of the given author, or ErrNotFound.

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

func (s *Store) PendingInvitationExists(ctx context.Context, email string) (bool, error)

PendingInvitationExists reports whether an invitation to the (normalized) email has been sent and not yet used to create an account.

func (*Store) PostByID

func (s *Store) PostByID(ctx context.Context, id string) (*model.Post, error)

PostByID returns a post, draft or published.

func (*Store) PostForEdit

func (s *Store) PostForEdit(ctx context.Context, id string) (*model.Post, error)

PostForEdit returns a post with its author, stats and linked URL loaded (post.User, post.PostStat, post.URL).

func (*Store) PostToRead

func (s *Store) PostToRead(ctx context.Context, id string) (*model.Post, error)

PostToRead returns a post, draft or published, with its author, stats and linked URL loaded (post.User, post.PostStat, post.URL).

func (*Store) PostWithAuthorAndURL

func (s *Store) PostWithAuthorAndURL(ctx context.Context, id string) (*model.Post, error)

PostWithAuthorAndURL returns a post with its author and linked URL loaded (post.User, post.URL).

func (*Store) PostsByAuthor

func (s *Store) PostsByAuthor(ctx context.Context, page PostsPage) ([]*model.Post, error)

PostsByAuthor returns an author's posts, newest ID first.

func (*Store) PostsForExport

func (s *Store) PostsForExport(ctx context.Context, authorID, postID string) ([]*model.Post, error)

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

func (s *Store) ProfileAbout(ctx context.Context, userID string) (string, error)

ProfileAbout returns the user's "About" text, or "" when there is none.

func (*Store) PromptForPost

func (s *Store) PromptForPost(ctx context.Context, postID string) (*model.PostPrompt, error)

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

func (s *Store) RecordSentEmail(ctx context.Context, email *model.SentEmail) (bool, error)

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

func (s *Store) RegistrationOpen(ctx context.Context) (bool, error)

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) SaveFeed

func (s *Store) SaveFeed(ctx context.Context, feed *model.RSSFeed) error

SaveFeed writes the feed's fields back.

func (*Store) SaveInvitation

func (s *Store) SaveInvitation(ctx context.Context, inv *model.UserInvitation) error

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

func (s *Store) SaveProfileAbout(ctx context.Context, userID, about string) error

SaveProfileAbout creates the user's "About" text or replaces it.

func (*Store) SaveSignupRequest

func (s *Store) SaveSignupRequest(ctx context.Context, r *model.UserSignupRequest) error

SaveSignupRequest writes every column of the waiting list entry.

func (*Store) SaveUser

func (s *Store) SaveUser(ctx context.Context, u *model.User, columns ...string) error

SaveUser writes the named columns of u, or all of them when none is named.

func (*Store) SaveUserStyle

func (s *Store) SaveUserStyle(ctx context.Context, userID, styles string) error

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

func (s *Store) SetRegistrationOpen(ctx context.Context, open bool) error

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

func (s *Store) ShareByID(ctx context.Context, id string) (*model.PostShare, error)

ShareByID returns a share with its post and the post's author loaded (share.Post, share.Post.User).

func (*Store) ShareOfPost

func (s *Store) ShareOfPost(ctx context.Context, postID string) (*model.PostShare, error)

ShareOfPost returns a post's share link, or nil when it has none.

func (*Store) SignupRequestByID

func (s *Store) SignupRequestByID(ctx context.Context, id string) (*model.UserSignupRequest, error)

SignupRequestByID returns a waiting list entry, or ErrNotFound.

func (*Store) SignupRequestEmailExists

func (s *Store) SignupRequestEmailExists(ctx context.Context, email string) (bool, error)

SignupRequestEmailExists reports whether the (normalized) email waits in the list.

func (*Store) StoreURL

func (s *Store) StoreURL(ctx context.Context, rawURL string) (*model.NormalizedURL, error)

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

func (s *Store) StyleReviewNote(ctx context.Context, id string) (*model.StyleReviewNote, error)

StyleReviewNote returns a note with its review loaded (note.Review).

func (*Store) StyleReviews

func (s *Store) StyleReviews(ctx context.Context, postID string) ([]*model.StyleReview, error)

StyleReviews returns a post's reviews, newest first, each with its notes in their order.

func (*Store) Subscribe

func (s *Store) Subscribe(ctx context.Context, userID, feedID string) error

Subscribe subscribes a user to a feed, keeping an existing subscription.

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

func (s *Store) SubscriberByID(ctx context.Context, id string) (*model.EmailSubscriber, error)

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) TwoHops

func (s *Store) TwoHops(ctx context.Context, userID string) ([]*Hop, error)

TwoHops returns every path of length two from userID.

func (*Store) Tx

func (s *Store) Tx(ctx context.Context, fn func(tx *Store) error) error

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

func (s *Store) UnconfirmedUserIDsCreatedBefore(ctx context.Context, t time.Time) ([]string, error)

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

func (s *Store) UpdatePost(ctx context.Context, post *model.Post) error

UpdatePost writes every column of an existing post.

func (*Store) UpdatePrompt

func (s *Store) UpdatePrompt(ctx context.Context, prompt *model.PostPrompt) error

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

func (s *Store) UpsertFeed(ctx context.Context, normalizedURL string) (*model.RSSFeed, error)

UpsertFeed returns the feed with this (already normalized) URL, creating it if nobody subscribed to it yet.

func (*Store) UpsertFeedItem

func (s *Store) UpsertFeedItem(ctx context.Context, item *model.RSSItem) (created bool, err error)

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

func (s *Store) UsePowChallenge(ctx context.Context, salt string, at time.Time) (bool, error)

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

func (s *Store) UserByAPIKey(ctx context.Context, key string) (*model.User, error)

UserByAPIKey returns the user an API key belongs to, or ErrNotFound.

func (*Store) UserByEmail

func (s *Store) UserByEmail(ctx context.Context, email string) (*model.User, error)

UserByEmail returns the user whose stored email is email, or ErrNotFound.

func (*Store) UserByID

func (s *Store) UserByID(ctx context.Context, id string) (*model.User, error)

UserByID returns the user, or ErrNotFound.

func (*Store) UserByUsername

func (s *Store) UserByUsername(ctx context.Context, username string) (*model.User, error)

UserByUsername returns the user with that username.

func (*Store) UserEmailExists

func (s *Store) UserEmailExists(ctx context.Context, email string) (bool, error)

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

func (s *Store) UserStyleByUsername(ctx context.Context, username string) (*model.UserStyle, error)

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

func (s *Store) UserStyleForUser(ctx context.Context, userID string) (*model.UserStyle, error)

UserStyleForUser returns the user's custom CSS row, or nil when they have none.

func (*Store) UsernameExists

func (s *Store) UsernameExists(ctx context.Context, username string) (bool, error)

UsernameExists reports whether an account has the username.

func (*Store) UsersByIDs

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

UsersByIDs returns the users with those IDs, in no particular order.

func (*Store) UsersByIDsNewestFirst

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

UsersByIDsNewestFirst returns the users with those IDs, the most recently signed up first.

func (*Store) WhitelistTarget

func (s *Store) WhitelistTarget(ctx context.Context, username string) (*model.User, error)

WhitelistTarget finds the user a whitelist grant is about, by username.

func (*Store) WhitelistedUsers

func (s *Store) WhitelistedUsers(ctx context.Context, whoID string) ([]*model.User, error)

WhitelistedUsers returns the users whoID has an open grant for.

func (*Store) WrongLoginTriesSince

func (s *Store) WrongLoginTriesSince(ctx context.Context, userID string, since time.Time) (int64, error)

WrongLoginTriesSince sums the wrong codes tried on the user's attempts created after since.

Jump to

Keyboard shortcuts

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