feat: update database queries for multiple folder management

- Replace single folder queries with multiple folder operations
- Add AddUserEbookFolder, GetUserEbookFolders, DeleteUserEbookFolder queries
- Regenerate Go code with sqlc
- Update models to include UserEbookFolders struct
This commit is contained in:
2026-01-23 09:02:47 -05:00
parent b5ec84c901
commit 9019e524e0
4 changed files with 118 additions and 1 deletions
+94
View File
@@ -11,6 +11,27 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
const AddUserEbookFolder = `-- name: AddUserEbookFolder :one
INSERT INTO user_ebook_folders (user_id, folder_path) VALUES ($1, $2) RETURNING id, user_id, folder_path, created_at
`
type AddUserEbookFolderParams struct {
UserID pgtype.UUID `db:"user_id" json:"user_id"`
FolderPath string `db:"folder_path" json:"folder_path"`
}
func (q *Queries) AddUserEbookFolder(ctx context.Context, arg AddUserEbookFolderParams) (UserEbookFolders, error) {
row := q.db.QueryRow(ctx, AddUserEbookFolder, arg.UserID, arg.FolderPath)
var i UserEbookFolders
err := row.Scan(
&i.ID,
&i.UserID,
&i.FolderPath,
&i.CreatedAt,
)
return i, err
}
const CreateEbook = `-- name: CreateEbook :one
INSERT INTO ebooks (title, author, isbn, description, file_path, file_size, mime_type, cover_image_path, series, series_number, tags, asin, date_published, publisher, contributors)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
@@ -177,6 +198,20 @@ func (q *Queries) DeleteReadingProgress(ctx context.Context, arg DeleteReadingPr
return err
}
const DeleteUserEbookFolder = `-- name: DeleteUserEbookFolder :exec
DELETE FROM user_ebook_folders WHERE user_id = $1 AND folder_path = $2
`
type DeleteUserEbookFolderParams struct {
UserID pgtype.UUID `db:"user_id" json:"user_id"`
FolderPath string `db:"folder_path" json:"folder_path"`
}
func (q *Queries) DeleteUserEbookFolder(ctx context.Context, arg DeleteUserEbookFolderParams) error {
_, err := q.db.Exec(ctx, DeleteUserEbookFolder, arg.UserID, arg.FolderPath)
return err
}
const GetEbook = `-- name: GetEbook :one
SELECT id, title, author, isbn, description, file_path, file_size, mime_type, cover_image_path, created_at, updated_at, series, series_number, tags, asin, date_published, publisher, contributors FROM ebooks WHERE id = $1
`
@@ -207,6 +242,36 @@ func (q *Queries) GetEbook(ctx context.Context, id pgtype.UUID) (Ebooks, error)
return i, err
}
const GetEbookByFilePath = `-- name: GetEbookByFilePath :one
SELECT id, title, author, isbn, description, file_path, file_size, mime_type, cover_image_path, created_at, updated_at, series, series_number, tags, asin, date_published, publisher, contributors FROM ebooks WHERE file_path = $1
`
func (q *Queries) GetEbookByFilePath(ctx context.Context, filePath string) (Ebooks, error) {
row := q.db.QueryRow(ctx, GetEbookByFilePath, filePath)
var i Ebooks
err := row.Scan(
&i.ID,
&i.Title,
&i.Author,
&i.Isbn,
&i.Description,
&i.FilePath,
&i.FileSize,
&i.MimeType,
&i.CoverImagePath,
&i.CreatedAt,
&i.UpdatedAt,
&i.Series,
&i.SeriesNumber,
&i.Tags,
&i.Asin,
&i.DatePublished,
&i.Publisher,
&i.Contributors,
)
return i, err
}
const GetEbookRating = `-- name: GetEbookRating :one
SELECT id, ebook_id, user_id, rating, created_at, updated_at FROM ebook_ratings WHERE ebook_id = $1 AND user_id = $2
`
@@ -383,6 +448,35 @@ func (q *Queries) GetUserByUsername(ctx context.Context, username string) (Users
return i, err
}
const GetUserEbookFolders = `-- name: GetUserEbookFolders :many
SELECT id, user_id, folder_path, created_at FROM user_ebook_folders WHERE user_id = $1 ORDER BY created_at
`
func (q *Queries) GetUserEbookFolders(ctx context.Context, userID pgtype.UUID) ([]UserEbookFolders, error) {
rows, err := q.db.Query(ctx, GetUserEbookFolders, userID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []UserEbookFolders{}
for rows.Next() {
var i UserEbookFolders
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.FolderPath,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const ListEbooks = `-- name: ListEbooks :many
SELECT id, title, author, isbn, description, file_path, file_size, mime_type, cover_image_path, created_at, updated_at, series, series_number, tags, asin, date_published, publisher, contributors FROM ebooks ORDER BY created_at DESC LIMIT $1 OFFSET $2
`