generate thumbnails
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS thumbnails;
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE thumbnails (
|
||||
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
file_id TEXT NOT NULL REFERENCES files(id) ON DELETE CASCADE,
|
||||
page_number INTEGER NOT NULL,
|
||||
resolution_label TEXT NOT NULL,
|
||||
width INTEGER NOT NULL,
|
||||
height INTEGER NOT NULL,
|
||||
storage_key TEXT NOT NULL,
|
||||
mime_type TEXT NOT NULL DEFAULT 'image/jpeg',
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_thumbnails_file_id ON thumbnails(file_id);
|
||||
CREATE UNIQUE INDEX idx_thumbnails_unique ON thumbnails(file_id, page_number, resolution_label);
|
||||
@@ -47,6 +47,18 @@ type Tag struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Thumbnail struct {
|
||||
ID string `json:"id"`
|
||||
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"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
-- 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 *;
|
||||
|
||||
-- name: GetThumbnailsByFileID :many
|
||||
SELECT * FROM thumbnails
|
||||
WHERE file_id = $1
|
||||
ORDER BY page_number ASC, resolution_label ASC;
|
||||
|
||||
-- name: GetThumbnailByID :one
|
||||
SELECT * FROM thumbnails
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: DeleteThumbnailsByFileID :exec
|
||||
DELETE FROM thumbnails WHERE file_id = $1;
|
||||
|
||||
-- name: GetThumbnailByFilePageResolution :one
|
||||
SELECT * FROM thumbnails
|
||||
WHERE file_id = $1 AND page_number = $2 AND resolution_label = $3
|
||||
LIMIT 1;
|
||||
@@ -0,0 +1,150 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user