db

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ItemToJSON

func ItemToJSON(item models.LibraryItem) map[string]interface{}

ItemToJSON converts a LibraryItem to a JSON-friendly map.

Types

type BlocklistEntry added in v1.0.0

type BlocklistEntry struct {
	ID          int64     `json:"id"`
	Title       string    `json:"title"`
	Source      string    `json:"source"`
	DownloadURL string    `json:"download_url"`
	InfoHash    string    `json:"info_hash"`
	Reason      string    `json:"reason"`
	CreatedAt   time.Time `json:"created_at"`
}

BlocklistEntry represents a blocklisted download.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps a SQLite database for library tracking and download jobs.

func New

func New(path string) (*DB, error)

New opens (or creates) the SQLite database at the given path.

func (*DB) AddBlocklistEntry added in v1.0.0

func (d *DB) AddBlocklistEntry(title, source, downloadURL, infoHash, reason string) (int64, error)

func (*DB) AddItem

func (d *DB) AddItem(item *models.LibraryItem) (int64, error)

AddItem records a successfully processed book.

func (*DB) AddItemTag added in v1.0.0

func (d *DB) AddItemTag(itemID, tagID int64) error

func (*DB) AddMonitoredAuthor added in v1.0.0

func (d *DB) AddMonitoredAuthor(name string, intervalDays int) (int64, error)

func (*DB) AddReadingHistory added in v1.0.0

func (d *DB) AddReadingHistory(userID int64, bookTitle, author, format string, startedAt, finishedAt *time.Time, rating *int, notes string, libraryItemID *int64) (int64, error)

AddReadingHistory inserts a reading history entry.

func (*DB) AddWishlistItem

func (d *DB) AddWishlistItem(title, author, mediaType string) (int64, error)

AddWishlistItem adds an item to the wishlist.

func (*DB) ClearBlocklist added in v1.0.0

func (d *DB) ClearBlocklist() error

func (*DB) ClearFinishedJobs

func (d *DB) ClearFinishedJobs() (int, error)

ClearFinishedJobs removes completed, error, and dead_letter jobs.

func (*DB) Close

func (d *DB) Close() error

Close closes the database connection.

func (*DB) CountActivity

func (d *DB) CountActivity() (int, error)

CountActivity returns the total number of activity events.

func (*DB) CountItems

func (d *DB) CountItems(mediaType string) (int, error)

CountItems counts library items, optionally filtered by media type.

func (*DB) CountRequests

func (d *DB) CountRequests(userID int64, status string) (int, error)

CountRequests returns the number of requests matching the filters.

func (*DB) CountUnreadNotifications

func (d *DB) CountUnreadNotifications(userID int64) (int, error)

CountUnreadNotifications returns the number of unread notifications for a user.

func (*DB) CountUsers

func (d *DB) CountUsers() (int, error)

CountUsers returns the total number of users.

func (*DB) CreateInviteCode added in v1.1.0

func (d *DB) CreateInviteCode(code string, createdBy int64, role string, maxUses int, expiresAt *float64) (int64, error)

CreateInviteCode generates a new invite code.

func (*DB) CreateNotification

func (d *DB) CreateNotification(n *models.Notification) (int64, error)

CreateNotification inserts a new notification.

func (*DB) CreateQualityProfile added in v1.0.0

func (d *DB) CreateQualityProfile(qp *QualityProfile) (int64, error)

func (*DB) CreateReleaseProfile added in v1.0.0

func (d *DB) CreateReleaseProfile(rp *ReleaseProfile) (int64, error)

func (*DB) CreateRequest

func (d *DB) CreateRequest(req *models.Request) error

CreateRequest inserts a new book request.

func (*DB) CreateTag added in v1.0.0

func (d *DB) CreateTag(name, color string) (int64, error)

func (*DB) CreateUser

func (d *DB) CreateUser(username, passwordHash, role string) (int64, error)

CreateUser inserts a new user. Returns the new user ID.

func (*DB) CreateWebhookConfig added in v1.0.0

func (d *DB) CreateWebhookConfig(c *webhook.Config) (int64, error)

CreateWebhookConfig inserts a new webhook config.

func (*DB) DeleteBlocklistEntry added in v1.0.0

func (d *DB) DeleteBlocklistEntry(id int64) error

func (*DB) DeleteInviteCode added in v1.1.0

func (d *DB) DeleteInviteCode(id int64) error

DeleteInviteCode removes an invite code.

func (*DB) DeleteItem

func (d *DB) DeleteItem(id int64) error

DeleteItem removes a library item by ID.

func (*DB) DeleteItemBySourceID added in v1.1.0

func (d *DB) DeleteItemBySourceID(sourceID string) error

DeleteItemBySourceID removes a library item by its source_id field.

func (*DB) DeleteJob

func (d *DB) DeleteJob(id string) error

DeleteJob removes a download job.

func (*DB) DeleteMonitoredAuthor added in v1.0.0

func (d *DB) DeleteMonitoredAuthor(id int64) error

func (*DB) DeleteNotification

func (d *DB) DeleteNotification(id int64, userID int64) error

DeleteNotification removes a notification by ID (must belong to user).

func (*DB) DeleteQualityProfile added in v1.0.0

func (d *DB) DeleteQualityProfile(id int64) error

func (*DB) DeleteReadingHistory added in v1.0.0

func (d *DB) DeleteReadingHistory(id, userID int64) error

DeleteReadingHistory removes a history entry by ID.

func (*DB) DeleteReleaseProfile added in v1.0.0

func (d *DB) DeleteReleaseProfile(id int64) error

func (*DB) DeleteRequest

func (d *DB) DeleteRequest(id string) error

DeleteRequest removes a request by ID.

func (*DB) DeleteTag added in v1.0.0

func (d *DB) DeleteTag(id int64) error

func (*DB) DeleteUser

func (d *DB) DeleteUser(id int64) error

DeleteUser removes a user by ID.

func (*DB) DeleteWebhookConfig added in v1.0.0

func (d *DB) DeleteWebhookConfig(id int64) error

DeleteWebhookConfig removes a webhook config by ID.

func (*DB) DeleteWishlistItem

func (d *DB) DeleteWishlistItem(id int64) error

DeleteWishlistItem removes a wishlist item by ID.

func (*DB) DisableTOTP

func (d *DB) DisableTOTP(userID int64) error

DisableTOTP disables TOTP and clears the secret.

func (*DB) EnableTOTP

func (d *DB) EnableTOTP(userID int64) error

EnableTOTP enables TOTP for a user.

func (*DB) FindByTitle

func (d *DB) FindByTitle(title string) ([]models.LibraryItem, error)

FindByTitle performs a case-insensitive title lookup.

func (*DB) GetActivity

func (d *DB) GetActivity(limit, offset int) ([]models.ActivityEvent, error)

GetActivity returns recent activity, newest first.

func (*DB) GetActivityLog

func (d *DB) GetActivityLog(user, action string, limit, offset int) ([]models.ActivityEntry, error)

GetActivityLog returns paginated activity entries with optional filters.

func (*DB) GetActivityLogCount

func (d *DB) GetActivityLogCount(user, action string) (int, error)

GetActivityLogCount returns the total number of activity entries matching filters.

func (*DB) GetBlocklist added in v1.0.0

func (d *DB) GetBlocklist(limit, offset int) ([]BlocklistEntry, error)

func (*DB) GetDBPath added in v1.0.0

func (d *DB) GetDBPath() string

GetDBPath returns the file path to the database.

func (*DB) GetItemTags added in v1.0.0

func (d *DB) GetItemTags(itemID int64) ([]Tag, error)

func (*DB) GetItems

func (d *DB) GetItems(mediaType string, limit, offset int) ([]models.LibraryItem, error)

GetItems returns a paginated list of library items, newest first.

func (*DB) GetItemsByTag added in v1.0.0

func (d *DB) GetItemsByTag(tagID int64, limit, offset int) ([]models.LibraryItem, error)

func (*DB) GetJob

func (d *DB) GetJob(id string) (*models.DownloadJob, error)

GetJob retrieves a download job by ID.

func (*DB) GetJobs

func (d *DB) GetJobs() ([]models.DownloadJob, error)

GetJobs returns all download jobs.

func (*DB) GetMonitoredAuthors added in v1.0.0

func (d *DB) GetMonitoredAuthors() ([]MonitoredAuthor, error)

func (*DB) GetNotifications

func (d *DB) GetNotifications(userID int64, limit, offset int) ([]models.Notification, error)

GetNotifications returns notifications for a user, newest first.

func (*DB) GetQualityProfile added in v1.0.0

func (d *DB) GetQualityProfile(id int64) (*QualityProfile, error)

func (*DB) GetQualityProfiles added in v1.0.0

func (d *DB) GetQualityProfiles() ([]QualityProfile, error)

func (*DB) GetReadingHistory added in v1.0.0

func (d *DB) GetReadingHistory(userID int64, status string, limit, offset int) ([]ReadingHistoryEntry, error)

GetReadingHistory returns paginated reading history for a user.

func (*DB) GetReadingStats added in v1.0.0

func (d *DB) GetReadingStats(userID int64) (map[string]interface{}, error)

GetReadingStats returns reading statistics for a user.

func (*DB) GetReleaseProfile added in v1.0.0

func (d *DB) GetReleaseProfile(id int64) (*ReleaseProfile, error)

func (*DB) GetReleaseProfiles added in v1.0.0

func (d *DB) GetReleaseProfiles() ([]ReleaseProfile, error)

func (*DB) GetRequest

func (d *DB) GetRequest(id string) (*models.Request, error)

GetRequest retrieves a request by ID.

func (*DB) GetSeriesTracking added in v1.0.0

func (d *DB) GetSeriesTracking() ([]map[string]interface{}, error)

GetSeriesTracking returns all tracked series.

func (*DB) GetStats

func (d *DB) GetStats() (map[string]interface{}, error)

GetStats returns collection statistics.

func (*DB) GetTags added in v1.0.0

func (d *DB) GetTags() ([]Tag, error)

func (*DB) GetUploads

func (d *DB) GetUploads(limit, offset int) ([]models.UploadRecord, error)

GetUploads returns recent uploads.

func (*DB) GetUser

func (d *DB) GetUser(id int64) (*models.User, error)

GetUser retrieves a user by ID.

func (*DB) GetUserByUsername

func (d *DB) GetUserByUsername(username string) (*models.User, error)

GetUserByUsername retrieves a user by username (case-insensitive).

func (*DB) GetWebhookConfigs added in v1.0.0

func (d *DB) GetWebhookConfigs() ([]webhook.Config, error)

GetWebhookConfigs returns all webhook configurations.

func (*DB) GetWishlist

func (d *DB) GetWishlist() ([]models.WishlistItem, error)

GetWishlist returns all wishlist items.

func (*DB) HasSourceID

func (d *DB) HasSourceID(sourceID string) bool

HasSourceID checks if a source_id already exists.

func (*DB) IsBlocklisted added in v1.0.0

func (d *DB) IsBlocklisted(downloadURL, infoHash string) bool

func (*DB) ListInviteCodes added in v1.1.0

func (d *DB) ListInviteCodes() ([]map[string]interface{}, error)

ListInviteCodes returns all invite codes for admin display.

func (*DB) ListRequests

func (d *DB) ListRequests(userID int64, status string, limit, offset int) ([]models.Request, error)

ListRequests returns requests filtered by optional user ID and status. If userID is 0, all requests are returned (admin view).

func (*DB) ListUsers

func (d *DB) ListUsers() ([]models.User, error)

ListUsers returns all users.

func (*DB) LogActivity

func (d *DB) LogActivity(user, action, target, detail string)

LogActivity appends a user-attributed event to the activity log.

func (*DB) LogEvent

func (d *DB) LogEvent(eventType, title, detail string, libraryItemID *int64, jobID string) error

LogEvent appends an event to the activity log.

func (*DB) MarkAllNotificationsRead

func (d *DB) MarkAllNotificationsRead(userID int64) error

MarkAllNotificationsRead marks all notifications as read for a user.

func (*DB) MarkNotificationRead

func (d *DB) MarkNotificationRead(id int64, userID int64) error

MarkNotificationRead marks a single notification as read.

func (*DB) RemoveItemTag added in v1.0.0

func (d *DB) RemoveItemTag(itemID, tagID int64) error

func (*DB) SaveBackupCodes

func (d *DB) SaveBackupCodes(userID int64, codeHashes []string) error

SaveBackupCodes stores hashed backup codes for a user.

func (*DB) SaveJob

func (d *DB) SaveJob(job *models.DownloadJob) error

SaveJob persists a download job.

func (*DB) SaveUpload

func (d *DB) SaveUpload(user, filename, originalName, fileType string, fileSize int64, organizedTo, status, errMsg string) (int64, error)

SaveUpload records a file upload.

func (*DB) SetTOTPSecret

func (d *DB) SetTOTPSecret(userID int64, secret string) error

SetTOTPSecret stores the TOTP secret for a user (does not enable it yet).

func (*DB) UpdateJobStatus

func (d *DB) UpdateJobStatus(id, status, detail, errMsg string) error

UpdateJobStatus updates the status and detail of a job.

func (*DB) UpdateLastLogin

func (d *DB) UpdateLastLogin(userID int64) error

UpdateLastLogin updates the last_login timestamp for a user.

func (*DB) UpdateMonitoredAuthorCheck added in v1.0.0

func (d *DB) UpdateMonitoredAuthorCheck(id int64, lastBookFound string) error

func (*DB) UpdateQualityProfile added in v1.0.0

func (d *DB) UpdateQualityProfile(qp *QualityProfile) error

func (*DB) UpdateReadingHistory added in v1.0.0

func (d *DB) UpdateReadingHistory(id, userID int64, finishedAt *time.Time, rating *int, notes *string) error

UpdateReadingHistory updates a history entry (finish date, rating, notes).

func (*DB) UpdateReleaseProfile added in v1.0.0

func (d *DB) UpdateReleaseProfile(rp *ReleaseProfile) error

func (*DB) UpdateRequest

func (d *DB) UpdateRequest(req *models.Request) error

UpdateRequest updates mutable fields on a request.

func (*DB) UpdateRequestStatus

func (d *DB) UpdateRequestStatus(id, status string) error

UpdateRequestStatus updates the status and optional fields of a request.

func (*DB) UpdateUser

func (d *DB) UpdateUser(id int64, username, role string) error

UpdateUser updates a user's username and role.

func (*DB) UpdateUserPassword

func (d *DB) UpdateUserPassword(id int64, passwordHash string) error

UpdateUserPassword updates only the password hash.

func (*DB) UpsertSeriesTracking added in v1.0.0

func (d *DB) UpsertSeriesTracking(seriesName string, knownTotal, ownedCount int) (int64, error)

UpsertSeriesTracking creates or updates a series tracking entry.

func (*DB) UseBackupCode

func (d *DB) UseBackupCode(userID int64, codeHash string) (bool, error)

UseBackupCode checks if a backup code matches any unused code for the user. If found, marks it used.

func (*DB) UseInviteCode added in v1.1.0

func (d *DB) UseInviteCode(code string) error

UseInviteCode increments the use count.

func (*DB) ValidateInviteCode added in v1.1.0

func (d *DB) ValidateInviteCode(code string) (string, error)

ValidateInviteCode checks if an invite code is valid (exists, not expired, uses remaining). Returns the role the new user should get, or an error.

type MonitoredAuthor added in v1.0.0

type MonitoredAuthor struct {
	ID                int64     `json:"id"`
	Name              string    `json:"name"`
	LastChecked       time.Time `json:"last_checked"`
	LastBookFound     string    `json:"last_book_found"`
	CheckIntervalDays int       `json:"check_interval_days"`
}

MonitoredAuthor represents a monitored author record.

type PreferredWord added in v1.0.0

type PreferredWord struct {
	Word  string `json:"word"`
	Score int    `json:"score"`
}

PreferredWord represents a word+score pair in a release profile.

type QualityProfile added in v1.0.0

type QualityProfile struct {
	ID               int64    `json:"id"`
	Name             string   `json:"name"`
	FormatRanking    []string `json:"format_ranking"`
	PreferredSizeMin int64    `json:"preferred_size_min"`
	PreferredSizeMax int64    `json:"preferred_size_max"`
	UpgradeAllowed   bool     `json:"upgrade_allowed"`
	CutoffFormat     string   `json:"cutoff_format"`
}

QualityProfile represents a quality profile record.

type ReadingHistoryEntry added in v1.0.0

type ReadingHistoryEntry struct {
	ID            int64      `json:"id"`
	UserID        int64      `json:"user_id"`
	BookTitle     string     `json:"book_title"`
	Author        string     `json:"author"`
	Format        string     `json:"format"`
	StartedAt     *time.Time `json:"started_at,omitempty"`
	FinishedAt    *time.Time `json:"finished_at,omitempty"`
	Rating        *int       `json:"rating,omitempty"`
	Notes         string     `json:"notes"`
	LibraryItemID *int64     `json:"library_item_id,omitempty"`
	Status        string     `json:"status"`
}

ReadingHistoryEntry represents a reading history record.

type ReleaseProfile added in v1.0.0

type ReleaseProfile struct {
	ID             int64           `json:"id"`
	Name           string          `json:"name"`
	MustContain    []string        `json:"must_contain"`
	MustNotContain []string        `json:"must_not_contain"`
	Preferred      []PreferredWord `json:"preferred"`
	Enabled        bool            `json:"enabled"`
}

ReleaseProfile represents a release profile record.

type Tag added in v1.0.0

type Tag struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
}

Tag represents a tag record.

Jump to

Keyboard shortcuts

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