158 lines
4.0 KiB
Go
158 lines
4.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: resource_variants.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createResourceVariant = `-- name: CreateResourceVariant :one
|
|
INSERT INTO resource_variants (resource_id, variant_type, page_number, width, height, mime_type, generated_by, storage_key)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
RETURNING id, resource_id, variant_type, page_number, width, height, mime_type, generated_by, storage_key, created_at
|
|
`
|
|
|
|
type CreateResourceVariantParams struct {
|
|
ResourceID uuid.UUID `json:"resource_id"`
|
|
VariantType string `json:"variant_type"`
|
|
PageNumber int32 `json:"page_number"`
|
|
Width int32 `json:"width"`
|
|
Height int32 `json:"height"`
|
|
MimeType string `json:"mime_type"`
|
|
GeneratedBy string `json:"generated_by"`
|
|
StorageKey string `json:"storage_key"`
|
|
}
|
|
|
|
func (q *Queries) CreateResourceVariant(ctx context.Context, arg CreateResourceVariantParams) (ResourceVariant, error) {
|
|
row := q.db.QueryRowContext(ctx, createResourceVariant,
|
|
arg.ResourceID,
|
|
arg.VariantType,
|
|
arg.PageNumber,
|
|
arg.Width,
|
|
arg.Height,
|
|
arg.MimeType,
|
|
arg.GeneratedBy,
|
|
arg.StorageKey,
|
|
)
|
|
var i ResourceVariant
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.VariantType,
|
|
&i.PageNumber,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.MimeType,
|
|
&i.GeneratedBy,
|
|
&i.StorageKey,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteVariantsByResourceID = `-- name: DeleteVariantsByResourceID :exec
|
|
DELETE FROM resource_variants WHERE resource_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteVariantsByResourceID(ctx context.Context, resourceID uuid.UUID) error {
|
|
_, err := q.db.ExecContext(ctx, deleteVariantsByResourceID, resourceID)
|
|
return err
|
|
}
|
|
|
|
const getBestVariant = `-- name: GetBestVariant :one
|
|
SELECT id, resource_id, variant_type, page_number, width, height, mime_type, generated_by, storage_key, created_at FROM resource_variants
|
|
WHERE resource_id = $1 AND variant_type = $2 AND page_number = 1
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetBestVariantParams struct {
|
|
ResourceID uuid.UUID `json:"resource_id"`
|
|
VariantType string `json:"variant_type"`
|
|
}
|
|
|
|
func (q *Queries) GetBestVariant(ctx context.Context, arg GetBestVariantParams) (ResourceVariant, error) {
|
|
row := q.db.QueryRowContext(ctx, getBestVariant, arg.ResourceID, arg.VariantType)
|
|
var i ResourceVariant
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.VariantType,
|
|
&i.PageNumber,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.MimeType,
|
|
&i.GeneratedBy,
|
|
&i.StorageKey,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getVariantByID = `-- name: GetVariantByID :one
|
|
SELECT id, resource_id, variant_type, page_number, width, height, mime_type, generated_by, storage_key, created_at FROM resource_variants
|
|
WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetVariantByID(ctx context.Context, id uuid.UUID) (ResourceVariant, error) {
|
|
row := q.db.QueryRowContext(ctx, getVariantByID, id)
|
|
var i ResourceVariant
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.VariantType,
|
|
&i.PageNumber,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.MimeType,
|
|
&i.GeneratedBy,
|
|
&i.StorageKey,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getVariantsByResourceID = `-- name: GetVariantsByResourceID :many
|
|
SELECT id, resource_id, variant_type, page_number, width, height, mime_type, generated_by, storage_key, created_at FROM resource_variants
|
|
WHERE resource_id = $1
|
|
ORDER BY page_number ASC, variant_type ASC
|
|
`
|
|
|
|
func (q *Queries) GetVariantsByResourceID(ctx context.Context, resourceID uuid.UUID) ([]ResourceVariant, error) {
|
|
rows, err := q.db.QueryContext(ctx, getVariantsByResourceID, resourceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ResourceVariant
|
|
for rows.Next() {
|
|
var i ResourceVariant
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.VariantType,
|
|
&i.PageNumber,
|
|
&i.Width,
|
|
&i.Height,
|
|
&i.MimeType,
|
|
&i.GeneratedBy,
|
|
&i.StorageKey,
|
|
&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
|
|
}
|