123 lines
2.8 KiB
Go
123 lines
2.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: ocr_jobs.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createOCRJob = `-- name: CreateOCRJob :one
|
|
INSERT INTO ocr_jobs (resource_id, file_path, status)
|
|
VALUES ($1, $2, 'pending')
|
|
RETURNING id, resource_id, file_path, status, error_message, created_at, updated_at
|
|
`
|
|
|
|
type CreateOCRJobParams struct {
|
|
ResourceID uuid.UUID `json:"resource_id"`
|
|
FilePath string `json:"file_path"`
|
|
}
|
|
|
|
func (q *Queries) CreateOCRJob(ctx context.Context, arg CreateOCRJobParams) (OcrJob, error) {
|
|
row := q.db.QueryRowContext(ctx, createOCRJob, arg.ResourceID, arg.FilePath)
|
|
var i OcrJob
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.FilePath,
|
|
&i.Status,
|
|
&i.ErrorMessage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteOCRJob = `-- name: DeleteOCRJob :exec
|
|
DELETE FROM ocr_jobs
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteOCRJob(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.ExecContext(ctx, deleteOCRJob, id)
|
|
return err
|
|
}
|
|
|
|
const getOCRJob = `-- name: GetOCRJob :one
|
|
SELECT id, resource_id, file_path, status, error_message, created_at, updated_at FROM ocr_jobs
|
|
WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetOCRJob(ctx context.Context, id uuid.UUID) (OcrJob, error) {
|
|
row := q.db.QueryRowContext(ctx, getOCRJob, id)
|
|
var i OcrJob
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.FilePath,
|
|
&i.Status,
|
|
&i.ErrorMessage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listPendingOCRJobs = `-- name: ListPendingOCRJobs :many
|
|
SELECT id, resource_id, file_path, status, error_message, created_at, updated_at FROM ocr_jobs
|
|
WHERE status = 'pending'
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
func (q *Queries) ListPendingOCRJobs(ctx context.Context) ([]OcrJob, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPendingOCRJobs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []OcrJob
|
|
for rows.Next() {
|
|
var i OcrJob
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.FilePath,
|
|
&i.Status,
|
|
&i.ErrorMessage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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
|
|
}
|
|
|
|
const updateOCRJobStatus = `-- name: UpdateOCRJobStatus :exec
|
|
UPDATE ocr_jobs
|
|
SET status = $1, error_message = $2, updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $3
|
|
`
|
|
|
|
type UpdateOCRJobStatusParams struct {
|
|
Status string `json:"status"`
|
|
ErrorMessage string `json:"error_message"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateOCRJobStatus(ctx context.Context, arg UpdateOCRJobStatusParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateOCRJobStatus, arg.Status, arg.ErrorMessage, arg.ID)
|
|
return err
|
|
}
|