repo

package
v0.0.0-...-2da20e2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package repo ...

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var ErrBatchInsertMissingColumn = errors.New("insert: missing column")

ErrBatchInsertMissingColumn indicates that a batch insert operation failed because one or more required columns were not provided.

View Source
var (
	// ErrBookNotFound is a sentinel error returned when book not found.
	ErrBookNotFound = app.ErrNotFound("book not found")
)
View Source
var (
	// ErrEmailConfirmationNotFound is a sentinel error returned when ds.EmailConfirmation not found.
	ErrEmailConfirmationNotFound = app.ErrNotFound("email confirmation not found")
)
View Source
var (
	// ErrEntityChangeRequestNotFound is a sentinel error returned when change request not found.
	ErrEntityChangeRequestNotFound = app.ErrNotFound("change request not found")
)
View Source
var (
	// ErrEntityNotFound is a sentinel error returned when entity is not found.
	ErrEntityNotFound = errors.New("entity not found")
)
View Source
var (
	// ErrEventLogNotFound is a sentinel error returned when EventLog not found.
	ErrEventLogNotFound = app.ErrNotFound("event log not found")
)
View Source
var (
	// ErrFileNotFound is a sentinel error returned when file not found.
	ErrFileNotFound = app.ErrNotFound("file not found")
)
View Source
var ErrInsertNoValues = errors.New("insert: no values")

ErrInsertNoValues indicates that an insert operation was attempted without providing any values to insert.

View Source
var (
	// ErrOAuthUserAccountNotFound is a sentinel error returned when a account lookup fails.
	ErrOAuthUserAccountNotFound = errors.New("oauth user account not found")
)
View Source
var (
	// ErrPageNotFound is a sentinel error returned when page not found.
	ErrPageNotFound = app.ErrNotFound("page not found")
)
View Source
var ErrSessionNotFound = app.ErrUnauthorized()

ErrSessionNotFound ...

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

func New(db *app.DB, t trace.Tracer) *Repo

New is a factory function that creates and returns a new Repo instance.

func (*Repo) ApplyChangesToBook

func (r *Repo) ApplyChangesToBook(ctx context.Context, id ds.ID, changes map[string]any) error

ApplyChangesToBook applies a map of changes to a Book record.

func (*Repo) ApplyChangesToEntity

func (r *Repo) ApplyChangesToEntity(ctx context.Context, id ds.ID, changes map[string]any) error

ApplyChangesToEntity applies a map of changes to an Entity record.

func (*Repo) ApplyChangesToPage

func (r *Repo) ApplyChangesToPage(ctx context.Context, id ds.ID, changes map[string]any) error

ApplyChangesToPage applies a map of changes to a Page record.

func (*Repo) AttachTopics

func (r *Repo) AttachTopics(ctx context.Context, entityID ds.ID, topics []ds.Topic) error

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

func (r *Repo) CommitChangeRequest(ctx context.Context, req *ds.EntityChangeRequest) error

CommitChangeRequest marks a change request as committed.

func (*Repo) CommitFile

func (r *Repo) CommitFile(ctx context.Context, fileID ds.ID) error

CommitFile ...

func (*Repo) CreateBook

func (r *Repo) CreateBook(ctx context.Context, b *ds.Book) error

CreateBook inserts a new book record into the database. The corresponding entity in the 'entities' table should be created separately.

func (*Repo) CreateChangeEmailRequest

func (r *Repo) CreateChangeEmailRequest(ctx context.Context, req *ds.ChangeEmailRequest) error

CreateChangeEmailRequest inserts a new change email request into the database.

func (*Repo) CreateChangeRequest

func (r *Repo) CreateChangeRequest(ctx context.Context, m *ds.EntityChangeRequest) error

CreateChangeRequest creates a new entity change request record.

func (*Repo) CreateEmailConfirmation

func (r *Repo) CreateEmailConfirmation(ctx context.Context, ec *ds.EmailConfirmation) (err error)

CreateEmailConfirmation creates a new email confirmation record in the database.

func (*Repo) CreateEntity

func (r *Repo) CreateEntity(ctx context.Context, e *ds.Entity) error

CreateEntity inserts entity.

func (*Repo) CreateEntityTopic

func (r *Repo) CreateEntityTopic(ctx context.Context, entityID, topicID ds.ID) error

CreateEntityTopic creates a single association between an entity and a topic.

func (*Repo) CreateEventLog

func (r *Repo) CreateEventLog(ctx context.Context, log *ds.EventLog) error

CreateEventLog persists an EventLog entry to the database.

func (*Repo) CreateFile

func (r *Repo) CreateFile(ctx context.Context, f *ds.File) error

CreateFile inserts a new file record into the database.

func (*Repo) CreateOAuthUserAccount

func (r *Repo) CreateOAuthUserAccount(ctx context.Context, acc *ds.OAuthUserAccount) (err error)

CreateOAuthUserAccount inserts a new user record into the database.

func (*Repo) CreatePage

func (r *Repo) CreatePage(ctx context.Context, p *ds.Page) error

CreatePage inserts a new page record into the database.

func (*Repo) CreatePasswordResetToken

func (r *Repo) CreatePasswordResetToken(ctx context.Context, t *ds.PasswordResetToken) error

CreatePasswordResetToken inserts a new password reset token into the database.

func (*Repo) CreateTopic

func (r *Repo) CreateTopic(ctx context.Context, t *ds.Topic) error

CreateTopic inserts a new topic record into the database.

func (*Repo) CreateUser

func (r *Repo) CreateUser(ctx context.Context, u *ds.User) (err error)

CreateUser inserts a new user record into the database.

func (*Repo) CreateUserSession

func (r *Repo) CreateUserSession(ctx context.Context, s *ds.UserSession) (err error)

CreateUserSession inserts a new user session record into the database.

func (*Repo) DeleteChangeEmailRequest

func (r *Repo) DeleteChangeEmailRequest(ctx context.Context, id ds.ID) error

DeleteChangeEmailRequest removes a change email request from the database by its ID.

func (*Repo) DeleteChangeEmailRequestsByUser

func (r *Repo) DeleteChangeEmailRequestsByUser(ctx context.Context, userID ds.ID) error

DeleteChangeEmailRequestsByUser removes a change email request for specific user.

func (*Repo) DeleteEmailConfirmation

func (r *Repo) DeleteEmailConfirmation(ctx context.Context, id ds.ID) (err error)

DeleteEmailConfirmation deletes an email confirmation record from the database using its ID.

func (*Repo) DeleteEmailConfirmationByUser

func (r *Repo) DeleteEmailConfirmationByUser(ctx context.Context, userID ds.ID) (err error)

DeleteEmailConfirmationByUser deletes an email confirmations that belong to specific user.

func (*Repo) DeleteEntity

func (r *Repo) DeleteEntity(ctx context.Context, id ds.ID) error

DeleteEntity marks an entity as deleted.

func (*Repo) DeleteFile

func (r *Repo) DeleteFile(ctx context.Context, id ds.ID) error

DeleteFile soft deletes a file.

func (*Repo) DeletePasswordResetToken

func (r *Repo) DeletePasswordResetToken(ctx context.Context, id ds.ID) error

DeletePasswordResetToken removes a password reset token from the database by its ID.

func (*Repo) DeletePasswordResetTokensByUser

func (r *Repo) DeletePasswordResetTokensByUser(ctx context.Context, userID ds.ID) error

DeletePasswordResetTokensByUser removes a password reset tokens that belongs to specific user.

func (*Repo) DeleteSessionsByUserID

func (r *Repo) DeleteSessionsByUserID(ctx context.Context, userID ds.ID) (err error)

DeleteSessionsByUserID removes all session records for a specific user from the database.

func (*Repo) DeleteUser

func (r *Repo) DeleteUser(ctx context.Context, userID ds.ID) (err error)

DeleteUser performs a soft delete on a user record by setting the deleted_at timestamp.

func (*Repo) DeleteUserSession

func (r *Repo) DeleteUserSession(ctx context.Context, id ds.ID) (err error)

DeleteUserSession removes a user session record from the database using its unique ID.

func (*Repo) DetachTopics

func (r *Repo) DetachTopics(ctx context.Context, entityID ds.ID) error

DetachTopics drops associations between an entity and topics.

func (*Repo) EntityTopics

func (r *Repo) EntityTopics(ctx context.Context, entityID ds.ID) ([]ds.Topic, error)

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

func (r *Repo) GetBookByID(ctx context.Context, id ds.ID) (*ds.Book, error)

GetBookByID retrieves a book by its ID.

func (*Repo) GetBookByPublicID

func (r *Repo) GetBookByPublicID(ctx context.Context, publicID string) (*ds.Book, error)

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

func (r *Repo) GetEntityByID(ctx context.Context, id ds.ID) (*ds.Entity, error)

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

func (r *Repo) GetEventLogByID(ctx context.Context, id ds.ID) (log *ds.EventLog, err error)

GetEventLogByID retrieves an event log by its ID.

func (*Repo) GetFileByHash

func (r *Repo) GetFileByHash(ctx context.Context, hash string) (*ds.File, error)

GetFileByHash retrieves a file by its hash.

func (*Repo) GetFileByID

func (r *Repo) GetFileByID(ctx context.Context, id ds.ID) (*ds.File, error)

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

func (r *Repo) GetPageByID(ctx context.Context, id ds.ID) (*ds.Page, error)

GetPageByID retrieves a page by its ID.

func (*Repo) GetPageByPublicID

func (r *Repo) GetPageByPublicID(ctx context.Context, publicID string) (*ds.Page, error)

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

func (r *Repo) GetUserByEmail(ctx context.Context, email string) (*ds.User, error)

GetUserByEmail retrieves a user from the database by their email address.

func (*Repo) GetUserByID

func (r *Repo) GetUserByID(ctx context.Context, id ds.ID) (*ds.User, error)

GetUserByID retrieves a user from the database by their ID.

func (*Repo) GetUserByUsername

func (r *Repo) GetUserByUsername(ctx context.Context, username string) (*ds.User, error)

GetUserByUsername retrieves a user from the database by their username.

func (*Repo) GetUserSessionByID

func (r *Repo) GetUserSessionByID(ctx context.Context, id ds.ID) (sess *ds.UserSession, err error)

GetUserSessionByID retrieves a user session record from the database using its unique ID.

func (*Repo) HardDeleteFile

func (r *Repo) HardDeleteFile(ctx context.Context, fileID ds.ID) (err error)

HardDeleteFile permanently deletes a file record from the database. Epstein and his friends would be jealous.

func (*Repo) ProlongUserSession

func (r *Repo) ProlongUserSession(ctx context.Context, id ds.ID) (err error)

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

func (r *Repo) SearchBookAuthors(ctx context.Context, query string) ([]ds.BookAuthor, error)

SearchBookAuthors searches book authors by name.

func (*Repo) SetUserEmailConfirmed

func (r *Repo) SetUserEmailConfirmed(ctx context.Context, userID ds.ID) (err error)

SetUserEmailConfirmed updates a user's record to set the email_confirmed flag to true and updates the updated_at timestamp.

func (*Repo) UpdateBook

func (r *Repo) UpdateBook(ctx context.Context, b *ds.Book) error

UpdateBook updates mutable fields of an existing book record.

func (*Repo) UpdateChangeRequest

func (r *Repo) UpdateChangeRequest(ctx context.Context, m *ds.EntityChangeRequest) error

UpdateChangeRequest updates an existing entity change request record.

func (*Repo) UpdateEntity

func (r *Repo) UpdateEntity(ctx context.Context, e *ds.Entity) error

UpdateEntity updates both entity and book tables.

func (*Repo) UpdateFilePreviewByHash

func (r *Repo) UpdateFilePreviewByHash(ctx context.Context, preview, hash string) error

UpdateFilePreviewByHash ...

func (*Repo) UpdatePage

func (r *Repo) UpdatePage(ctx context.Context, p *ds.Page) error

UpdatePage updates the stored content of an existing page.

func (*Repo) UpdateUser

func (r *Repo) UpdateUser(ctx context.Context, u *ds.User) error

UpdateUser updates user fields in the database.

func (*Repo) UpdateUserEmail

func (r *Repo) UpdateUserEmail(ctx context.Context, userID ds.ID, email string) (err error)

UpdateUserEmail updates the email for a specific user.

func (*Repo) UpdateUserPassword

func (r *Repo) UpdateUserPassword(ctx context.Context, userID ds.ID, password string) (err error)

UpdateUserPassword updates the password hash for a specific user.

func (*Repo) UpdateUsername

func (r *Repo) UpdateUsername(ctx context.Context, userID ds.ID, username string) (err error)

UpdateUsername updates the username for a specific user.

func (*Repo) WithTx

func (r *Repo) WithTx(ctx context.Context, fn func(ctx context.Context) error) error

WithTx wraps app.RunInTx and puts the transaction into the context.

Jump to

Keyboard shortcuts

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