Documentation
¶
Overview ¶
Package repo ...
Index ¶
- Variables
- type DBI
- type Repo
- func (r *Repo) ApplyChangesToBook(ctx context.Context, id ds.ID, changes map[string]any) error
- func (r *Repo) ApplyChangesToEntity(ctx context.Context, id ds.ID, changes map[string]any) error
- func (r *Repo) ApplyChangesToPage(ctx context.Context, id ds.ID, changes map[string]any) error
- func (r *Repo) AttachTopics(ctx context.Context, entityID ds.ID, topics []ds.Topic) error
- func (r *Repo) ChangeEntityStatus(ctx context.Context, entityID ds.ID, status ds.EntityStatus) error
- func (r *Repo) CommitChangeRequest(ctx context.Context, req *ds.EntityChangeRequest) error
- func (r *Repo) CommitFile(ctx context.Context, fileID ds.ID) error
- func (r *Repo) CreateBook(ctx context.Context, b *ds.Book) error
- func (r *Repo) CreateChangeEmailRequest(ctx context.Context, req *ds.ChangeEmailRequest) error
- func (r *Repo) CreateChangeRequest(ctx context.Context, m *ds.EntityChangeRequest) error
- func (r *Repo) CreateEmailConfirmation(ctx context.Context, ec *ds.EmailConfirmation) (err error)
- func (r *Repo) CreateEntity(ctx context.Context, e *ds.Entity) error
- func (r *Repo) CreateEntityTopic(ctx context.Context, entityID, topicID ds.ID) error
- func (r *Repo) CreateEventLog(ctx context.Context, log *ds.EventLog) error
- func (r *Repo) CreateFile(ctx context.Context, f *ds.File) error
- func (r *Repo) CreateOAuthUserAccount(ctx context.Context, acc *ds.OAuthUserAccount) (err error)
- func (r *Repo) CreatePage(ctx context.Context, p *ds.Page) error
- func (r *Repo) CreatePasswordResetToken(ctx context.Context, t *ds.PasswordResetToken) error
- func (r *Repo) CreateTopic(ctx context.Context, t *ds.Topic) error
- func (r *Repo) CreateUser(ctx context.Context, u *ds.User) (err error)
- func (r *Repo) CreateUserSession(ctx context.Context, s *ds.UserSession) (err error)
- func (r *Repo) DeleteChangeEmailRequest(ctx context.Context, id ds.ID) error
- func (r *Repo) DeleteChangeEmailRequestsByUser(ctx context.Context, userID ds.ID) error
- func (r *Repo) DeleteEmailConfirmation(ctx context.Context, id ds.ID) (err error)
- func (r *Repo) DeleteEmailConfirmationByUser(ctx context.Context, userID ds.ID) (err error)
- func (r *Repo) DeleteEntity(ctx context.Context, id ds.ID) error
- func (r *Repo) DeleteFile(ctx context.Context, id ds.ID) error
- func (r *Repo) DeletePasswordResetToken(ctx context.Context, id ds.ID) error
- func (r *Repo) DeletePasswordResetTokensByUser(ctx context.Context, userID ds.ID) error
- func (r *Repo) DeleteSessionsByUserID(ctx context.Context, userID ds.ID) (err error)
- func (r *Repo) DeleteUser(ctx context.Context, userID ds.ID) (err error)
- func (r *Repo) DeleteUserSession(ctx context.Context, id ds.ID) (err error)
- func (r *Repo) DetachTopics(ctx context.Context, entityID ds.ID) error
- func (r *Repo) EntityTopics(ctx context.Context, entityID ds.ID) ([]ds.Topic, error)
- func (r *Repo) FilterBooks(ctx context.Context, f ds.BooksFilter) (books []ds.Book, count int, err error)
- func (r *Repo) FilterChangeRequests(ctx context.Context, f ds.ChangeRequestsFilter) (reqs []ds.EntityChangeRequest, count int, err error)
- func (r *Repo) FilterEventLogs(ctx context.Context, f ds.EventLogsFilter) (logs []ds.EventLog, count int, err error)
- func (r *Repo) FilterFiles(ctx context.Context, f ds.FilesFilter) (files []ds.File, count int, err error)
- func (r *Repo) FilterTopics(ctx context.Context, f ds.TopicsFilter) (data []ds.Topic, count int, err error)
- func (r *Repo) FilterUsers(ctx context.Context, f ds.UsersFilter) (users []ds.User, count int, err error)
- func (r *Repo) GetBookByID(ctx context.Context, id ds.ID) (*ds.Book, error)
- func (r *Repo) GetBookByPublicID(ctx context.Context, publicID string) (*ds.Book, error)
- func (r *Repo) GetChangeEmailRequestByToken(ctx context.Context, token string) (*ds.ChangeEmailRequest, error)
- func (r *Repo) GetChangeRequestByID(ctx context.Context, id ds.ID) (req *ds.EntityChangeRequest, err error)
- func (r *Repo) GetEmailConfirmationByCode(ctx context.Context, code string) (ec *ds.EmailConfirmation, err error)
- func (r *Repo) GetEntityByID(ctx context.Context, id ds.ID) (*ds.Entity, error)
- func (r *Repo) GetEntityByPublicID(ctx context.Context, publicID string, t ds.EntityType) (*ds.Entity, error)
- func (r *Repo) GetEventLogByID(ctx context.Context, id ds.ID) (log *ds.EventLog, err error)
- func (r *Repo) GetFileByHash(ctx context.Context, hash string) (*ds.File, error)
- func (r *Repo) GetFileByID(ctx context.Context, id ds.ID) (*ds.File, error)
- func (r *Repo) GetLatestEmailConfirmationByUserID(ctx context.Context, userID ds.ID) (*ds.EmailConfirmation, error)
- func (r *Repo) GetOAuthUserAccount(ctx context.Context, prov provider.Type, provUserID string) (*ds.OAuthUserAccount, error)
- func (r *Repo) GetPageByID(ctx context.Context, id ds.ID) (*ds.Page, error)
- func (r *Repo) GetPageByPublicID(ctx context.Context, publicID string) (*ds.Page, error)
- func (r *Repo) GetPagesByPublicID(ctx context.Context, publicIDs ...string) (pages []ds.Page, err error)
- func (r *Repo) GetPasswordResetToken(ctx context.Context, token string) (*ds.PasswordResetToken, error)
- func (r *Repo) GetPendingChangeRequest(ctx context.Context, entityID, userID ds.ID) (*ds.EntityChangeRequest, error)
- func (r *Repo) GetUserByEmail(ctx context.Context, email string) (*ds.User, error)
- func (r *Repo) GetUserByID(ctx context.Context, id ds.ID) (*ds.User, error)
- func (r *Repo) GetUserByUsername(ctx context.Context, username string) (*ds.User, error)
- func (r *Repo) GetUserSessionByID(ctx context.Context, id ds.ID) (sess *ds.UserSession, err error)
- func (r *Repo) HardDeleteFile(ctx context.Context, fileID ds.ID) (err error)
- func (r *Repo) ProlongUserSession(ctx context.Context, id ds.ID) (err error)
- func (r *Repo) RejectChangeRequest(ctx context.Context, id, reviewerID ds.ID, note string) (err error)
- func (r *Repo) SearchBookAuthors(ctx context.Context, query string) ([]ds.BookAuthor, error)
- func (r *Repo) SetUserEmailConfirmed(ctx context.Context, userID ds.ID) (err error)
- func (r *Repo) UpdateBook(ctx context.Context, b *ds.Book) error
- func (r *Repo) UpdateChangeRequest(ctx context.Context, m *ds.EntityChangeRequest) error
- func (r *Repo) UpdateEntity(ctx context.Context, e *ds.Entity) error
- func (r *Repo) UpdateFilePreviewByHash(ctx context.Context, preview, hash string) error
- func (r *Repo) UpdatePage(ctx context.Context, p *ds.Page) error
- func (r *Repo) UpdateUser(ctx context.Context, u *ds.User) error
- func (r *Repo) UpdateUserEmail(ctx context.Context, userID ds.ID, email string) (err error)
- func (r *Repo) UpdateUserPassword(ctx context.Context, userID ds.ID, password string) (err error)
- func (r *Repo) UpdateUsername(ctx context.Context, userID ds.ID, username string) (err error)
- func (r *Repo) WithTx(ctx context.Context, fn func(ctx context.Context) error) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUserNotFound is a sentinel error returned when a user lookup fails. ErrUserNotFound = errors.New("user not found") // ErrPasswordResetTokenNotFound is a sentinel error returned when a password reset token is not found. ErrPasswordResetTokenNotFound = errors.New("password reset token not found") // ErrChangeEmailRequestNotFound ... ErrChangeEmailRequestNotFound = errors.New("change email request not found") )
var ErrBatchInsertMissingColumn = errors.New("insert: missing column")
ErrBatchInsertMissingColumn indicates that a batch insert operation failed because one or more required columns were not provided.
var ( // ErrBookNotFound is a sentinel error returned when book not found. ErrBookNotFound = app.ErrNotFound("book not found") )
var ( // ErrEmailConfirmationNotFound is a sentinel error returned when ds.EmailConfirmation not found. ErrEmailConfirmationNotFound = app.ErrNotFound("email confirmation not found") )
var ( // ErrEntityChangeRequestNotFound is a sentinel error returned when change request not found. ErrEntityChangeRequestNotFound = app.ErrNotFound("change request not found") )
var ( // ErrEntityNotFound is a sentinel error returned when entity is not found. ErrEntityNotFound = errors.New("entity not found") )
var ( // ErrEventLogNotFound is a sentinel error returned when EventLog not found. ErrEventLogNotFound = app.ErrNotFound("event log not found") )
var ( // ErrFileNotFound is a sentinel error returned when file not found. ErrFileNotFound = app.ErrNotFound("file not found") )
var ErrInsertNoValues = errors.New("insert: no values")
ErrInsertNoValues indicates that an insert operation was attempted without providing any values to insert.
var ( // ErrOAuthUserAccountNotFound is a sentinel error returned when a account lookup fails. ErrOAuthUserAccountNotFound = errors.New("oauth user account not found") )
var ( // ErrPageNotFound is a sentinel error returned when page not found. ErrPageNotFound = app.ErrNotFound("page not found") )
var ErrSessionNotFound = app.ErrUnauthorized()
ErrSessionNotFound ...
var ( // ErrTopicFound is a sentinel error returned when topic not found. ErrTopicFound = app.ErrNotFound("topic not found") )
Functions ¶
This section is empty.
Types ¶
type DBI ¶
type DBI interface {
Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}
DBI matches the common methods between pgxpool.Pool and pgx.Tx. This allows repository methods to work whether they are in a transaction or not.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo is the primary struct for database access operations All repository methods are attached to this type.
func (*Repo) ApplyChangesToBook ¶
ApplyChangesToBook applies a map of changes to a Book record.
func (*Repo) ApplyChangesToEntity ¶
ApplyChangesToEntity applies a map of changes to an Entity record.
func (*Repo) ApplyChangesToPage ¶
ApplyChangesToPage applies a map of changes to a Page record.
func (*Repo) AttachTopics ¶
AttachTopics creates associations between an entity and the given topics.
func (*Repo) ChangeEntityStatus ¶
func (r *Repo) ChangeEntityStatus(ctx context.Context, entityID ds.ID, status ds.EntityStatus) error
ChangeEntityStatus updates the status field of the specified entity.
func (*Repo) CommitChangeRequest ¶
CommitChangeRequest marks a change request as committed.
func (*Repo) CommitFile ¶
CommitFile ...
func (*Repo) CreateBook ¶
CreateBook inserts a new book record into the database. The corresponding entity in the 'entities' table should be created separately.
func (*Repo) CreateChangeEmailRequest ¶
CreateChangeEmailRequest inserts a new change email request into the database.
func (*Repo) CreateChangeRequest ¶
CreateChangeRequest creates a new entity change request record.
func (*Repo) CreateEmailConfirmation ¶
CreateEmailConfirmation creates a new email confirmation record in the database.
func (*Repo) CreateEntity ¶
CreateEntity inserts entity.
func (*Repo) CreateEntityTopic ¶
CreateEntityTopic creates a single association between an entity and a topic.
func (*Repo) CreateEventLog ¶
CreateEventLog persists an EventLog entry to the database.
func (*Repo) CreateFile ¶
CreateFile inserts a new file record into the database.
func (*Repo) CreateOAuthUserAccount ¶
CreateOAuthUserAccount inserts a new user record into the database.
func (*Repo) CreatePage ¶
CreatePage inserts a new page record into the database.
func (*Repo) CreatePasswordResetToken ¶
CreatePasswordResetToken inserts a new password reset token into the database.
func (*Repo) CreateTopic ¶
CreateTopic inserts a new topic record into the database.
func (*Repo) CreateUser ¶
CreateUser inserts a new user record into the database.
func (*Repo) CreateUserSession ¶
CreateUserSession inserts a new user session record into the database.
func (*Repo) DeleteChangeEmailRequest ¶
DeleteChangeEmailRequest removes a change email request from the database by its ID.
func (*Repo) DeleteChangeEmailRequestsByUser ¶
DeleteChangeEmailRequestsByUser removes a change email request for specific user.
func (*Repo) DeleteEmailConfirmation ¶
DeleteEmailConfirmation deletes an email confirmation record from the database using its ID.
func (*Repo) DeleteEmailConfirmationByUser ¶
DeleteEmailConfirmationByUser deletes an email confirmations that belong to specific user.
func (*Repo) DeleteEntity ¶
DeleteEntity marks an entity as deleted.
func (*Repo) DeleteFile ¶
DeleteFile soft deletes a file.
func (*Repo) DeletePasswordResetToken ¶
DeletePasswordResetToken removes a password reset token from the database by its ID.
func (*Repo) DeletePasswordResetTokensByUser ¶
DeletePasswordResetTokensByUser removes a password reset tokens that belongs to specific user.
func (*Repo) DeleteSessionsByUserID ¶
DeleteSessionsByUserID removes all session records for a specific user from the database.
func (*Repo) DeleteUser ¶
DeleteUser performs a soft delete on a user record by setting the deleted_at timestamp.
func (*Repo) DeleteUserSession ¶
DeleteUserSession removes a user session record from the database using its unique ID.
func (*Repo) DetachTopics ¶
DetachTopics drops associations between an entity and topics.
func (*Repo) EntityTopics ¶
EntityTopics returns all non-deleted topics associated with the given entity.
func (*Repo) FilterBooks ¶
func (r *Repo) FilterBooks(ctx context.Context, f ds.BooksFilter) (books []ds.Book, count int, err error)
FilterBooks retrieves a paginated list of books matching the given filter.
func (*Repo) FilterChangeRequests ¶
func (r *Repo) FilterChangeRequests(ctx context.Context, f ds.ChangeRequestsFilter) (reqs []ds.EntityChangeRequest, count int, err error)
FilterChangeRequests retrieves a paginated list of change requests matching the given filter.
func (*Repo) FilterEventLogs ¶
func (r *Repo) FilterEventLogs(ctx context.Context, f ds.EventLogsFilter) (logs []ds.EventLog, count int, err error)
FilterEventLogs retrieves a paginated list of event logs matching the given filter.
func (*Repo) FilterFiles ¶
func (r *Repo) FilterFiles(ctx context.Context, f ds.FilesFilter) (files []ds.File, count int, err error)
FilterFiles ...
func (*Repo) FilterTopics ¶
func (r *Repo) FilterTopics(ctx context.Context, f ds.TopicsFilter) (data []ds.Topic, count int, err error)
FilterTopics retrieves a paginated list of topics matching the given filter.
func (*Repo) FilterUsers ¶
func (r *Repo) FilterUsers(ctx context.Context, f ds.UsersFilter) (users []ds.User, count int, err error)
FilterUsers retrieves a paginated, filtered list of users from the database.
func (*Repo) GetBookByID ¶
GetBookByID retrieves a book by its ID.
func (*Repo) GetBookByPublicID ¶
GetBookByPublicID retrieves a book by its public ID.
func (*Repo) GetChangeEmailRequestByToken ¶
func (r *Repo) GetChangeEmailRequestByToken(ctx context.Context, token string) (*ds.ChangeEmailRequest, error)
GetChangeEmailRequestByToken retrieves a change email request from the database by its token. If the token is not found, it returns ErrChangeEmailRequestNotFound.
func (*Repo) GetChangeRequestByID ¶
func (r *Repo) GetChangeRequestByID(ctx context.Context, id ds.ID) (req *ds.EntityChangeRequest, err error)
GetChangeRequestByID retrieves an entity change request by its ID.
func (*Repo) GetEmailConfirmationByCode ¶
func (r *Repo) GetEmailConfirmationByCode(ctx context.Context, code string) (ec *ds.EmailConfirmation, err error)
GetEmailConfirmationByCode retrieves an email confirmation record from the database using its unique confirmation code. If a record is not found, it returns (nil, nil).
func (*Repo) GetEntityByID ¶
GetEntityByID retrieves an entity by its ID.
func (*Repo) GetEntityByPublicID ¶
func (r *Repo) GetEntityByPublicID(ctx context.Context, publicID string, t ds.EntityType) (*ds.Entity, error)
GetEntityByPublicID retrieves an entity by its URL-friendly name.
func (*Repo) GetEventLogByID ¶
GetEventLogByID retrieves an event log by its ID.
func (*Repo) GetFileByHash ¶
GetFileByHash retrieves a file by its hash.
func (*Repo) GetFileByID ¶
GetFileByID retrieves a file by its ID.
func (*Repo) GetLatestEmailConfirmationByUserID ¶
func (r *Repo) GetLatestEmailConfirmationByUserID(ctx context.Context, userID ds.ID) (*ds.EmailConfirmation, error)
GetLatestEmailConfirmationByUserID returns the most recent email confirmation record for the given user.
func (*Repo) GetOAuthUserAccount ¶
func (r *Repo) GetOAuthUserAccount( ctx context.Context, prov provider.Type, provUserID string) (*ds.OAuthUserAccount, error)
GetOAuthUserAccount ...
func (*Repo) GetPageByID ¶
GetPageByID retrieves a page by its ID.
func (*Repo) GetPageByPublicID ¶
GetPageByPublicID retrieves a page by its public ID.
func (*Repo) GetPagesByPublicID ¶
func (r *Repo) GetPagesByPublicID(ctx context.Context, publicIDs ...string) (pages []ds.Page, err error)
GetPagesByPublicID retrieves pages by given public ID.
func (*Repo) GetPasswordResetToken ¶
func (r *Repo) GetPasswordResetToken(ctx context.Context, token string) (*ds.PasswordResetToken, error)
GetPasswordResetToken retrieves a password reset token from the database by the token string. If the token is not found, it returns ErrPasswordResetTokenNotFound.
func (*Repo) GetPendingChangeRequest ¶
func (r *Repo) GetPendingChangeRequest(ctx context.Context, entityID, userID ds.ID) (*ds.EntityChangeRequest, error)
GetPendingChangeRequest retrieves the most recent pending change request for a specific entity and user.
func (*Repo) GetUserByEmail ¶
GetUserByEmail retrieves a user from the database by their email address.
func (*Repo) GetUserByID ¶
GetUserByID retrieves a user from the database by their ID.
func (*Repo) GetUserByUsername ¶
GetUserByUsername retrieves a user from the database by their username.
func (*Repo) GetUserSessionByID ¶
GetUserSessionByID retrieves a user session record from the database using its unique ID.
func (*Repo) HardDeleteFile ¶
HardDeleteFile permanently deletes a file record from the database. Epstein and his friends would be jealous.
func (*Repo) ProlongUserSession ¶
ProlongUserSession updates the expiration timestamp of an existing user session.
func (*Repo) RejectChangeRequest ¶
func (r *Repo) RejectChangeRequest(ctx context.Context, id, reviewerID ds.ID, note string) (err error)
RejectChangeRequest marks a change request as rejected.
func (*Repo) SearchBookAuthors ¶
SearchBookAuthors searches book authors by name.
func (*Repo) SetUserEmailConfirmed ¶
SetUserEmailConfirmed updates a user's record to set the email_confirmed flag to true and updates the updated_at timestamp.
func (*Repo) UpdateBook ¶
UpdateBook updates mutable fields of an existing book record.
func (*Repo) UpdateChangeRequest ¶
UpdateChangeRequest updates an existing entity change request record.
func (*Repo) UpdateEntity ¶
UpdateEntity updates both entity and book tables.
func (*Repo) UpdateFilePreviewByHash ¶
UpdateFilePreviewByHash ...
func (*Repo) UpdatePage ¶
UpdatePage updates the stored content of an existing page.
func (*Repo) UpdateUser ¶
UpdateUser updates user fields in the database.
func (*Repo) UpdateUserEmail ¶
UpdateUserEmail updates the email for a specific user.
func (*Repo) UpdateUserPassword ¶
UpdateUserPassword updates the password hash for a specific user.
func (*Repo) UpdateUsername ¶
UpdateUsername updates the username for a specific user.