151 lines
3.8 KiB
Go
151 lines
3.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: thumbnails.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const createThumbnail = `-- name: CreateThumbnail :one
|
|
INSERT INTO thumbnails (file_id, page_number, resolution_label, width, height, storage_key, mime_type)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING id, file_id, page_number, resolution_label, width, height, storage_key, mime_type, created_at
|
|
`
|
|
|
|
type CreateThumbnailParams struct {
|
|
FileID string `json:"file_id"`
|
|
PageNumber int32 `json:"page_number"`
|
|
ResolutionLabel string `json:"resolution_label"`
|
|
Width int32 `json:"width"`
|
|
Height int32 `json:"height"`
|
|
StorageKey string `json:"storage_key"`
|
|
MimeType string `json:"mime_type"`
|
|
}
|
|
|
|
func (q *Queries) CreateThumbnail(ctx context.Context, arg CreateThumbnailParams) (Thumbnail, error) {
|
|
row := q.db.QueryRowContext(ctx, createThumbnail,
|
|
arg.FileID,
|
|
arg.PageNumber,
|
|
arg.ResolutionLabel,
|
|
arg.Width,
|
|
arg.Height,
|
|
arg.StorageKey,
|
|
arg.MimeType,
|
|
)
|
|
var i Thumbnail
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FileID,
|
|
&i.PageNumber,
|
|
&i.ResolutionLabel,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.StorageKey,
|
|
&i.MimeType,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteThumbnailsByFileID = `-- name: DeleteThumbnailsByFileID :exec
|
|
DELETE FROM thumbnails WHERE file_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteThumbnailsByFileID(ctx context.Context, fileID string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteThumbnailsByFileID, fileID)
|
|
return err
|
|
}
|
|
|
|
const getThumbnailByFilePageResolution = `-- name: GetThumbnailByFilePageResolution :one
|
|
SELECT id, file_id, page_number, resolution_label, width, height, storage_key, mime_type, created_at FROM thumbnails
|
|
WHERE file_id = $1 AND page_number = $2 AND resolution_label = $3
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetThumbnailByFilePageResolutionParams struct {
|
|
FileID string `json:"file_id"`
|
|
PageNumber int32 `json:"page_number"`
|
|
ResolutionLabel string `json:"resolution_label"`
|
|
}
|
|
|
|
func (q *Queries) GetThumbnailByFilePageResolution(ctx context.Context, arg GetThumbnailByFilePageResolutionParams) (Thumbnail, error) {
|
|
row := q.db.QueryRowContext(ctx, getThumbnailByFilePageResolution, arg.FileID, arg.PageNumber, arg.ResolutionLabel)
|
|
var i Thumbnail
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FileID,
|
|
&i.PageNumber,
|
|
&i.ResolutionLabel,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.StorageKey,
|
|
&i.MimeType,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getThumbnailByID = `-- name: GetThumbnailByID :one
|
|
SELECT id, file_id, page_number, resolution_label, width, height, storage_key, mime_type, created_at FROM thumbnails
|
|
WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetThumbnailByID(ctx context.Context, id string) (Thumbnail, error) {
|
|
row := q.db.QueryRowContext(ctx, getThumbnailByID, id)
|
|
var i Thumbnail
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FileID,
|
|
&i.PageNumber,
|
|
&i.ResolutionLabel,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.StorageKey,
|
|
&i.MimeType,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getThumbnailsByFileID = `-- name: GetThumbnailsByFileID :many
|
|
SELECT id, file_id, page_number, resolution_label, width, height, storage_key, mime_type, created_at FROM thumbnails
|
|
WHERE file_id = $1
|
|
ORDER BY page_number ASC, resolution_label ASC
|
|
`
|
|
|
|
func (q *Queries) GetThumbnailsByFileID(ctx context.Context, fileID string) ([]Thumbnail, error) {
|
|
rows, err := q.db.QueryContext(ctx, getThumbnailsByFileID, fileID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Thumbnail
|
|
for rows.Next() {
|
|
var i Thumbnail
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.FileID,
|
|
&i.PageNumber,
|
|
&i.ResolutionLabel,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.StorageKey,
|
|
&i.MimeType,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|