436 lines
13 KiB
Go
436 lines
13 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: batch.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const addFailedFilename = `-- name: AddFailedFilename :exec
|
|
UPDATE batch_uploads
|
|
SET failed_filenames = failed_filenames || jsonb_build_array($2::text)
|
|
WHERE id = $1
|
|
`
|
|
|
|
type AddFailedFilenameParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Column2 string `db:"column_2"`
|
|
}
|
|
|
|
// AddFailedFilename
|
|
//
|
|
// UPDATE batch_uploads
|
|
// SET failed_filenames = failed_filenames || jsonb_build_array($2::text)
|
|
// WHERE id = $1
|
|
func (q *Queries) AddFailedFilename(ctx context.Context, arg *AddFailedFilenameParams) error {
|
|
_, err := q.db.Exec(ctx, addFailedFilename, arg.ID, arg.Column2)
|
|
return err
|
|
}
|
|
|
|
const cancelBatchUpload = `-- name: CancelBatchUpload :exec
|
|
UPDATE batch_uploads
|
|
SET status = 'cancelled',
|
|
completed_at = NOW()
|
|
WHERE id = $1 AND client_id = $2 AND status = 'processing'
|
|
`
|
|
|
|
type CancelBatchUploadParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ClientID string `db:"client_id"`
|
|
}
|
|
|
|
// CancelBatchUpload
|
|
//
|
|
// UPDATE batch_uploads
|
|
// SET status = 'cancelled',
|
|
// completed_at = NOW()
|
|
// WHERE id = $1 AND client_id = $2 AND status = 'processing'
|
|
func (q *Queries) CancelBatchUpload(ctx context.Context, arg *CancelBatchUploadParams) error {
|
|
_, err := q.db.Exec(ctx, cancelBatchUpload, arg.ID, arg.ClientID)
|
|
return err
|
|
}
|
|
|
|
const countDocumentsByBatchId = `-- name: CountDocumentsByBatchId :one
|
|
SELECT COUNT(*) as count
|
|
FROM documents
|
|
WHERE batch_id = $1
|
|
`
|
|
|
|
// CountDocumentsByBatchId
|
|
//
|
|
// SELECT COUNT(*) as count
|
|
// FROM documents
|
|
// WHERE batch_id = $1
|
|
func (q *Queries) CountDocumentsByBatchId(ctx context.Context, batchID *uuid.UUID) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countDocumentsByBatchId, batchID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createBatchUpload = `-- name: CreateBatchUpload :one
|
|
INSERT INTO batch_uploads (client_id, original_filename, total_documents)
|
|
VALUES ($1, $2, $3) RETURNING id
|
|
`
|
|
|
|
type CreateBatchUploadParams struct {
|
|
ClientID string `db:"client_id"`
|
|
OriginalFilename string `db:"original_filename"`
|
|
TotalDocuments int32 `db:"total_documents"`
|
|
}
|
|
|
|
// CreateBatchUpload
|
|
//
|
|
// INSERT INTO batch_uploads (client_id, original_filename, total_documents)
|
|
// VALUES ($1, $2, $3) RETURNING id
|
|
func (q *Queries) CreateBatchUpload(ctx context.Context, arg *CreateBatchUploadParams) (uuid.UUID, error) {
|
|
row := q.db.QueryRow(ctx, createBatchUpload, arg.ClientID, arg.OriginalFilename, arg.TotalDocuments)
|
|
var id uuid.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const createBatchUploadWithStorage = `-- name: CreateBatchUploadWithStorage :one
|
|
INSERT INTO batch_uploads (
|
|
client_id,
|
|
original_filename,
|
|
total_documents,
|
|
status,
|
|
archive_bucket,
|
|
archive_key,
|
|
file_size_bytes
|
|
) VALUES ($1, $2, $3, $4::batch_status, $5, $6, $7)
|
|
RETURNING id, created_at
|
|
`
|
|
|
|
type CreateBatchUploadWithStorageParams struct {
|
|
ClientID string `db:"client_id"`
|
|
OriginalFilename string `db:"original_filename"`
|
|
TotalDocuments int32 `db:"total_documents"`
|
|
Column4 BatchStatus `db:"column_4"`
|
|
ArchiveBucket *string `db:"archive_bucket"`
|
|
ArchiveKey *string `db:"archive_key"`
|
|
FileSizeBytes *int64 `db:"file_size_bytes"`
|
|
}
|
|
|
|
type CreateBatchUploadWithStorageRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
CreatedAt pgtype.Timestamp `db:"created_at"`
|
|
}
|
|
|
|
// CreateBatchUploadWithStorage
|
|
//
|
|
// INSERT INTO batch_uploads (
|
|
// client_id,
|
|
// original_filename,
|
|
// total_documents,
|
|
// status,
|
|
// archive_bucket,
|
|
// archive_key,
|
|
// file_size_bytes
|
|
// ) VALUES ($1, $2, $3, $4::batch_status, $5, $6, $7)
|
|
// RETURNING id, created_at
|
|
func (q *Queries) CreateBatchUploadWithStorage(ctx context.Context, arg *CreateBatchUploadWithStorageParams) (*CreateBatchUploadWithStorageRow, error) {
|
|
row := q.db.QueryRow(ctx, createBatchUploadWithStorage,
|
|
arg.ClientID,
|
|
arg.OriginalFilename,
|
|
arg.TotalDocuments,
|
|
arg.Column4,
|
|
arg.ArchiveBucket,
|
|
arg.ArchiveKey,
|
|
arg.FileSizeBytes,
|
|
)
|
|
var i CreateBatchUploadWithStorageRow
|
|
err := row.Scan(&i.ID, &i.CreatedAt)
|
|
return &i, err
|
|
}
|
|
|
|
const getBatchUpload = `-- name: GetBatchUpload :one
|
|
SELECT id, client_id, original_filename, total_documents, processed_documents,
|
|
failed_documents, invalid_type_documents, status, progress_percent,
|
|
failed_filenames, created_at, completed_at
|
|
FROM batch_uploads
|
|
WHERE id = $1 AND client_id = $2
|
|
`
|
|
|
|
type GetBatchUploadParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ClientID string `db:"client_id"`
|
|
}
|
|
|
|
type GetBatchUploadRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ClientID string `db:"client_id"`
|
|
OriginalFilename string `db:"original_filename"`
|
|
TotalDocuments int32 `db:"total_documents"`
|
|
ProcessedDocuments int32 `db:"processed_documents"`
|
|
FailedDocuments int32 `db:"failed_documents"`
|
|
InvalidTypeDocuments int32 `db:"invalid_type_documents"`
|
|
Status BatchStatus `db:"status"`
|
|
ProgressPercent int32 `db:"progress_percent"`
|
|
FailedFilenames []byte `db:"failed_filenames"`
|
|
CreatedAt pgtype.Timestamp `db:"created_at"`
|
|
CompletedAt pgtype.Timestamp `db:"completed_at"`
|
|
}
|
|
|
|
// GetBatchUpload
|
|
//
|
|
// SELECT id, client_id, original_filename, total_documents, processed_documents,
|
|
// failed_documents, invalid_type_documents, status, progress_percent,
|
|
// failed_filenames, created_at, completed_at
|
|
// FROM batch_uploads
|
|
// WHERE id = $1 AND client_id = $2
|
|
func (q *Queries) GetBatchUpload(ctx context.Context, arg *GetBatchUploadParams) (*GetBatchUploadRow, error) {
|
|
row := q.db.QueryRow(ctx, getBatchUpload, arg.ID, arg.ClientID)
|
|
var i GetBatchUploadRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ClientID,
|
|
&i.OriginalFilename,
|
|
&i.TotalDocuments,
|
|
&i.ProcessedDocuments,
|
|
&i.FailedDocuments,
|
|
&i.InvalidTypeDocuments,
|
|
&i.Status,
|
|
&i.ProgressPercent,
|
|
&i.FailedFilenames,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getBatchUploadWithStorage = `-- name: GetBatchUploadWithStorage :one
|
|
SELECT id, client_id, original_filename, total_documents,
|
|
processed_documents, failed_documents, invalid_type_documents,
|
|
status, archive_bucket, archive_key, file_size_bytes,
|
|
failed_filenames, created_at, completed_at
|
|
FROM batch_uploads
|
|
WHERE id = $1 AND client_id = $2
|
|
`
|
|
|
|
type GetBatchUploadWithStorageParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ClientID string `db:"client_id"`
|
|
}
|
|
|
|
type GetBatchUploadWithStorageRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ClientID string `db:"client_id"`
|
|
OriginalFilename string `db:"original_filename"`
|
|
TotalDocuments int32 `db:"total_documents"`
|
|
ProcessedDocuments int32 `db:"processed_documents"`
|
|
FailedDocuments int32 `db:"failed_documents"`
|
|
InvalidTypeDocuments int32 `db:"invalid_type_documents"`
|
|
Status BatchStatus `db:"status"`
|
|
ArchiveBucket *string `db:"archive_bucket"`
|
|
ArchiveKey *string `db:"archive_key"`
|
|
FileSizeBytes *int64 `db:"file_size_bytes"`
|
|
FailedFilenames []byte `db:"failed_filenames"`
|
|
CreatedAt pgtype.Timestamp `db:"created_at"`
|
|
CompletedAt pgtype.Timestamp `db:"completed_at"`
|
|
}
|
|
|
|
// GetBatchUploadWithStorage
|
|
//
|
|
// SELECT id, client_id, original_filename, total_documents,
|
|
// processed_documents, failed_documents, invalid_type_documents,
|
|
// status, archive_bucket, archive_key, file_size_bytes,
|
|
// failed_filenames, created_at, completed_at
|
|
// FROM batch_uploads
|
|
// WHERE id = $1 AND client_id = $2
|
|
func (q *Queries) GetBatchUploadWithStorage(ctx context.Context, arg *GetBatchUploadWithStorageParams) (*GetBatchUploadWithStorageRow, error) {
|
|
row := q.db.QueryRow(ctx, getBatchUploadWithStorage, arg.ID, arg.ClientID)
|
|
var i GetBatchUploadWithStorageRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ClientID,
|
|
&i.OriginalFilename,
|
|
&i.TotalDocuments,
|
|
&i.ProcessedDocuments,
|
|
&i.FailedDocuments,
|
|
&i.InvalidTypeDocuments,
|
|
&i.Status,
|
|
&i.ArchiveBucket,
|
|
&i.ArchiveKey,
|
|
&i.FileSizeBytes,
|
|
&i.FailedFilenames,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getDocumentsByBatchId = `-- name: GetDocumentsByBatchId :many
|
|
SELECT id, clientId, hash
|
|
FROM documents
|
|
WHERE batch_id = $1
|
|
`
|
|
|
|
type GetDocumentsByBatchIdRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Hash string `db:"hash"`
|
|
}
|
|
|
|
// GetDocumentsByBatchId
|
|
//
|
|
// SELECT id, clientId, hash
|
|
// FROM documents
|
|
// WHERE batch_id = $1
|
|
func (q *Queries) GetDocumentsByBatchId(ctx context.Context, batchID *uuid.UUID) ([]*GetDocumentsByBatchIdRow, error) {
|
|
rows, err := q.db.Query(ctx, getDocumentsByBatchId, batchID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*GetDocumentsByBatchIdRow{}
|
|
for rows.Next() {
|
|
var i GetDocumentsByBatchIdRow
|
|
if err := rows.Scan(&i.ID, &i.Clientid, &i.Hash); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listBatchUploads = `-- name: ListBatchUploads :many
|
|
SELECT id, client_id, original_filename, total_documents, processed_documents,
|
|
failed_documents, invalid_type_documents, status, progress_percent,
|
|
created_at, completed_at
|
|
FROM batch_uploads
|
|
WHERE client_id = $1
|
|
ORDER BY created_at DESC
|
|
LIMIT $2 OFFSET $3
|
|
`
|
|
|
|
type ListBatchUploadsParams struct {
|
|
ClientID string `db:"client_id"`
|
|
Limit int64 `db:"limit"`
|
|
Offset int64 `db:"offset"`
|
|
}
|
|
|
|
type ListBatchUploadsRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ClientID string `db:"client_id"`
|
|
OriginalFilename string `db:"original_filename"`
|
|
TotalDocuments int32 `db:"total_documents"`
|
|
ProcessedDocuments int32 `db:"processed_documents"`
|
|
FailedDocuments int32 `db:"failed_documents"`
|
|
InvalidTypeDocuments int32 `db:"invalid_type_documents"`
|
|
Status BatchStatus `db:"status"`
|
|
ProgressPercent int32 `db:"progress_percent"`
|
|
CreatedAt pgtype.Timestamp `db:"created_at"`
|
|
CompletedAt pgtype.Timestamp `db:"completed_at"`
|
|
}
|
|
|
|
// ListBatchUploads
|
|
//
|
|
// SELECT id, client_id, original_filename, total_documents, processed_documents,
|
|
// failed_documents, invalid_type_documents, status, progress_percent,
|
|
// created_at, completed_at
|
|
// FROM batch_uploads
|
|
// WHERE client_id = $1
|
|
// ORDER BY created_at DESC
|
|
// LIMIT $2 OFFSET $3
|
|
func (q *Queries) ListBatchUploads(ctx context.Context, arg *ListBatchUploadsParams) ([]*ListBatchUploadsRow, error) {
|
|
rows, err := q.db.Query(ctx, listBatchUploads, arg.ClientID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListBatchUploadsRow{}
|
|
for rows.Next() {
|
|
var i ListBatchUploadsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ClientID,
|
|
&i.OriginalFilename,
|
|
&i.TotalDocuments,
|
|
&i.ProcessedDocuments,
|
|
&i.FailedDocuments,
|
|
&i.InvalidTypeDocuments,
|
|
&i.Status,
|
|
&i.ProgressPercent,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBatchProgress = `-- name: UpdateBatchProgress :exec
|
|
UPDATE batch_uploads
|
|
SET processed_documents = $2,
|
|
failed_documents = $3,
|
|
invalid_type_documents = $4,
|
|
progress_percent = $5
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateBatchProgressParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
ProcessedDocuments int32 `db:"processed_documents"`
|
|
FailedDocuments int32 `db:"failed_documents"`
|
|
InvalidTypeDocuments int32 `db:"invalid_type_documents"`
|
|
ProgressPercent int32 `db:"progress_percent"`
|
|
}
|
|
|
|
// UpdateBatchProgress
|
|
//
|
|
// UPDATE batch_uploads
|
|
// SET processed_documents = $2,
|
|
// failed_documents = $3,
|
|
// invalid_type_documents = $4,
|
|
// progress_percent = $5
|
|
// WHERE id = $1
|
|
func (q *Queries) UpdateBatchProgress(ctx context.Context, arg *UpdateBatchProgressParams) error {
|
|
_, err := q.db.Exec(ctx, updateBatchProgress,
|
|
arg.ID,
|
|
arg.ProcessedDocuments,
|
|
arg.FailedDocuments,
|
|
arg.InvalidTypeDocuments,
|
|
arg.ProgressPercent,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateBatchStatus = `-- name: UpdateBatchStatus :exec
|
|
UPDATE batch_uploads
|
|
SET status = $2::batch_status,
|
|
completed_at = CASE WHEN $2::batch_status IN ('completed', 'failed', 'cancelled') THEN NOW() ELSE NULL END
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateBatchStatusParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Column2 BatchStatus `db:"column_2"`
|
|
}
|
|
|
|
// UpdateBatchStatus
|
|
//
|
|
// UPDATE batch_uploads
|
|
// SET status = $2::batch_status,
|
|
// completed_at = CASE WHEN $2::batch_status IN ('completed', 'failed', 'cancelled') THEN NOW() ELSE NULL END
|
|
// WHERE id = $1
|
|
func (q *Queries) UpdateBatchStatus(ctx context.Context, arg *UpdateBatchStatusParams) error {
|
|
_, err := q.db.Exec(ctx, updateBatchStatus, arg.ID, arg.Column2)
|
|
return err
|
|
}
|