ebf47c6013
track file sizes for all documents in system * feature complete needs dev testing
530 lines
14 KiB
Go
530 lines
14 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: document.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const addDocumentEntry = `-- name: AddDocumentEntry :exec
|
|
INSERT INTO documentEntries (documentId, bucket, key) VALUES ($1, $2, $3)
|
|
`
|
|
|
|
type AddDocumentEntryParams struct {
|
|
Documentid uuid.UUID `db:"documentid"`
|
|
Bucket string `db:"bucket"`
|
|
Key string `db:"key"`
|
|
}
|
|
|
|
// AddDocumentEntry
|
|
//
|
|
// INSERT INTO documentEntries (documentId, bucket, key) VALUES ($1, $2, $3)
|
|
func (q *Queries) AddDocumentEntry(ctx context.Context, arg *AddDocumentEntryParams) error {
|
|
_, err := q.db.Exec(ctx, addDocumentEntry, arg.Documentid, arg.Bucket, arg.Key)
|
|
return err
|
|
}
|
|
|
|
const addDocumentUpload = `-- name: AddDocumentUpload :exec
|
|
INSERT INTO documentUploads (id, clientId, bucket, key, part, createdAt, filename, batch_id, folder_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
`
|
|
|
|
type AddDocumentUploadParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Bucket string `db:"bucket"`
|
|
Key string `db:"key"`
|
|
Part uint16 `db:"part"`
|
|
Createdat pgtype.Timestamp `db:"createdat"`
|
|
Filename *string `db:"filename"`
|
|
BatchID *uuid.UUID `db:"batch_id"`
|
|
FolderID *uuid.UUID `db:"folder_id"`
|
|
}
|
|
|
|
// AddDocumentUpload
|
|
//
|
|
// INSERT INTO documentUploads (id, clientId, bucket, key, part, createdAt, filename, batch_id, folder_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
func (q *Queries) AddDocumentUpload(ctx context.Context, arg *AddDocumentUploadParams) error {
|
|
_, err := q.db.Exec(ctx, addDocumentUpload,
|
|
arg.ID,
|
|
arg.Clientid,
|
|
arg.Bucket,
|
|
arg.Key,
|
|
arg.Part,
|
|
arg.Createdat,
|
|
arg.Filename,
|
|
arg.BatchID,
|
|
arg.FolderID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const createDocument = `-- name: CreateDocument :one
|
|
INSERT INTO documents (clientId, hash, batch_id, filename, folderId, originalPath, file_size_bytes) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id
|
|
`
|
|
|
|
type CreateDocumentParams struct {
|
|
Clientid string `db:"clientid"`
|
|
Hash string `db:"hash"`
|
|
BatchID *uuid.UUID `db:"batch_id"`
|
|
Filename *string `db:"filename"`
|
|
Folderid *uuid.UUID `db:"folderid"`
|
|
Originalpath *string `db:"originalpath"`
|
|
FileSizeBytes *int64 `db:"file_size_bytes"`
|
|
}
|
|
|
|
// CreateDocument
|
|
//
|
|
// INSERT INTO documents (clientId, hash, batch_id, filename, folderId, originalPath, file_size_bytes) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id
|
|
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (uuid.UUID, error) {
|
|
row := q.db.QueryRow(ctx, createDocument,
|
|
arg.Clientid,
|
|
arg.Hash,
|
|
arg.BatchID,
|
|
arg.Filename,
|
|
arg.Folderid,
|
|
arg.Originalpath,
|
|
arg.FileSizeBytes,
|
|
)
|
|
var id uuid.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const getDocumentEnriched = `-- name: GetDocumentEnriched :one
|
|
SELECT
|
|
d.id,
|
|
d.clientId,
|
|
d.hash,
|
|
d.folderId,
|
|
d.filename,
|
|
d.originalPath,
|
|
d.file_size_bytes
|
|
FROM documents d
|
|
WHERE d.id = $1
|
|
`
|
|
|
|
type GetDocumentEnrichedRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Hash string `db:"hash"`
|
|
Folderid *uuid.UUID `db:"folderid"`
|
|
Filename *string `db:"filename"`
|
|
Originalpath *string `db:"originalpath"`
|
|
FileSizeBytes *int64 `db:"file_size_bytes"`
|
|
}
|
|
|
|
// Retrieves a document with extended metadata including folder and filename
|
|
//
|
|
// SELECT
|
|
// d.id,
|
|
// d.clientId,
|
|
// d.hash,
|
|
// d.folderId,
|
|
// d.filename,
|
|
// d.originalPath,
|
|
// d.file_size_bytes
|
|
// FROM documents d
|
|
// WHERE d.id = $1
|
|
func (q *Queries) GetDocumentEnriched(ctx context.Context, id uuid.UUID) (*GetDocumentEnrichedRow, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentEnriched, id)
|
|
var i GetDocumentEnrichedRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Clientid,
|
|
&i.Hash,
|
|
&i.Folderid,
|
|
&i.Filename,
|
|
&i.Originalpath,
|
|
&i.FileSizeBytes,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getDocumentEntry = `-- name: GetDocumentEntry :one
|
|
SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER BY id DESC LIMIT 1
|
|
`
|
|
|
|
type GetDocumentEntryRow struct {
|
|
Documentid uuid.UUID `db:"documentid"`
|
|
Bucket string `db:"bucket"`
|
|
Key string `db:"key"`
|
|
}
|
|
|
|
// GetDocumentEntry
|
|
//
|
|
// SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER BY id DESC LIMIT 1
|
|
func (q *Queries) GetDocumentEntry(ctx context.Context, documentid uuid.UUID) (*GetDocumentEntryRow, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentEntry, documentid)
|
|
var i GetDocumentEntryRow
|
|
err := row.Scan(&i.Documentid, &i.Bucket, &i.Key)
|
|
return &i, err
|
|
}
|
|
|
|
const getDocumentExternal = `-- name: GetDocumentExternal :one
|
|
WITH
|
|
docs AS (
|
|
SELECT id, hash, clientId
|
|
FROM documents
|
|
WHERE id = $1
|
|
),
|
|
namedResults AS (
|
|
SELECT
|
|
q.name,
|
|
dd.id,
|
|
d.value
|
|
FROM currentCollectorQueries AS q
|
|
JOIN docs as dd on dd.clientId = q.clientId
|
|
LEFT JOIN listValidDocumentResults($1) AS d
|
|
ON d.queryId = q.queryId and q.name is not null
|
|
)
|
|
SELECT
|
|
d.id,
|
|
d.clientId,
|
|
d.hash,
|
|
COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
|
|
FROM docs AS d
|
|
LEFT JOIN namedResults AS r ON d.id = r.id
|
|
GROUP BY d.id, d.clientId, d.hash
|
|
`
|
|
|
|
type GetDocumentExternalRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Hash string `db:"hash"`
|
|
Fields []byte `db:"fields"`
|
|
}
|
|
|
|
// GetDocumentExternal
|
|
//
|
|
// WITH
|
|
// docs AS (
|
|
// SELECT id, hash, clientId
|
|
// FROM documents
|
|
// WHERE id = $1
|
|
// ),
|
|
// namedResults AS (
|
|
// SELECT
|
|
// q.name,
|
|
// dd.id,
|
|
// d.value
|
|
// FROM currentCollectorQueries AS q
|
|
// JOIN docs as dd on dd.clientId = q.clientId
|
|
// LEFT JOIN listValidDocumentResults($1) AS d
|
|
// ON d.queryId = q.queryId and q.name is not null
|
|
// )
|
|
// SELECT
|
|
// d.id,
|
|
// d.clientId,
|
|
// d.hash,
|
|
// COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
|
|
// FROM docs AS d
|
|
// LEFT JOIN namedResults AS r ON d.id = r.id
|
|
// GROUP BY d.id, d.clientId, d.hash
|
|
func (q *Queries) GetDocumentExternal(ctx context.Context, documentid uuid.UUID) (*GetDocumentExternalRow, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentExternal, documentid)
|
|
var i GetDocumentExternalRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Clientid,
|
|
&i.Hash,
|
|
&i.Fields,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getDocumentIDByHash = `-- name: GetDocumentIDByHash :one
|
|
SELECT id FROM documents WHERE hash = $1 and clientId = $2
|
|
`
|
|
|
|
type GetDocumentIDByHashParams struct {
|
|
Hash string `db:"hash"`
|
|
Clientid string `db:"clientid"`
|
|
}
|
|
|
|
// GetDocumentIDByHash
|
|
//
|
|
// SELECT id FROM documents WHERE hash = $1 and clientId = $2
|
|
func (q *Queries) GetDocumentIDByHash(ctx context.Context, arg *GetDocumentIDByHashParams) (uuid.UUID, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentIDByHash, arg.Hash, arg.Clientid)
|
|
var id uuid.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const getDocumentSummary = `-- name: GetDocumentSummary :one
|
|
SELECT id, clientId, hash FROM documents WHERE id = $1
|
|
`
|
|
|
|
type GetDocumentSummaryRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Hash string `db:"hash"`
|
|
}
|
|
|
|
// GetDocumentSummary
|
|
//
|
|
// SELECT id, clientId, hash FROM documents WHERE id = $1
|
|
func (q *Queries) GetDocumentSummary(ctx context.Context, id uuid.UUID) (*GetDocumentSummaryRow, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentSummary, id)
|
|
var i GetDocumentSummaryRow
|
|
err := row.Scan(&i.ID, &i.Clientid, &i.Hash)
|
|
return &i, err
|
|
}
|
|
|
|
const getDocumentUploadByKey = `-- name: GetDocumentUploadByKey :one
|
|
SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id, folder_id FROM documentUploads WHERE bucket = $1 AND key = $2 LIMIT 1
|
|
`
|
|
|
|
type GetDocumentUploadByKeyParams struct {
|
|
Bucket string `db:"bucket"`
|
|
Key string `db:"key"`
|
|
}
|
|
|
|
type GetDocumentUploadByKeyRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Bucket string `db:"bucket"`
|
|
Key string `db:"key"`
|
|
Part uint16 `db:"part"`
|
|
Createdat pgtype.Timestamp `db:"createdat"`
|
|
Filename *string `db:"filename"`
|
|
BatchID *uuid.UUID `db:"batch_id"`
|
|
FolderID *uuid.UUID `db:"folder_id"`
|
|
}
|
|
|
|
// GetDocumentUploadByKey
|
|
//
|
|
// SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id, folder_id FROM documentUploads WHERE bucket = $1 AND key = $2 LIMIT 1
|
|
func (q *Queries) GetDocumentUploadByKey(ctx context.Context, arg *GetDocumentUploadByKeyParams) (*GetDocumentUploadByKeyRow, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentUploadByKey, arg.Bucket, arg.Key)
|
|
var i GetDocumentUploadByKeyRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Clientid,
|
|
&i.Bucket,
|
|
&i.Key,
|
|
&i.Part,
|
|
&i.Createdat,
|
|
&i.Filename,
|
|
&i.BatchID,
|
|
&i.FolderID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getDocumentUploadCurrentPart = `-- name: GetDocumentUploadCurrentPart :one
|
|
WITH client as (
|
|
select clientId from clients where clientId = $1
|
|
),
|
|
parts as (
|
|
SELECT docs.part
|
|
FROM client as c
|
|
JOIN documentUploads as docs on docs.clientId = c.clientId
|
|
WHERE date(docs.createdAt) = date($2)
|
|
),
|
|
max_part as (
|
|
SELECT COALESCE(max(part), 0) as max_part_num FROM parts
|
|
)
|
|
SELECT
|
|
COALESCE(p.part, 0)::unsignedsmallint as part,
|
|
COUNT(p.part) as count
|
|
FROM parts p
|
|
RIGHT JOIN max_part mp ON p.part = mp.max_part_num
|
|
GROUP BY p.part
|
|
`
|
|
|
|
type GetDocumentUploadCurrentPartParams struct {
|
|
Clientid *string `db:"clientid"`
|
|
Querydate pgtype.Timestamptz `db:"querydate"`
|
|
}
|
|
|
|
type GetDocumentUploadCurrentPartRow struct {
|
|
Part uint16 `db:"part"`
|
|
Count int64 `db:"count"`
|
|
}
|
|
|
|
// GetDocumentUploadCurrentPart
|
|
//
|
|
// WITH client as (
|
|
// select clientId from clients where clientId = $1
|
|
// ),
|
|
// parts as (
|
|
// SELECT docs.part
|
|
// FROM client as c
|
|
// JOIN documentUploads as docs on docs.clientId = c.clientId
|
|
// WHERE date(docs.createdAt) = date($2)
|
|
// ),
|
|
// max_part as (
|
|
// SELECT COALESCE(max(part), 0) as max_part_num FROM parts
|
|
// )
|
|
// SELECT
|
|
// COALESCE(p.part, 0)::unsignedsmallint as part,
|
|
// COUNT(p.part) as count
|
|
// FROM parts p
|
|
// RIGHT JOIN max_part mp ON p.part = mp.max_part_num
|
|
// GROUP BY p.part
|
|
func (q *Queries) GetDocumentUploadCurrentPart(ctx context.Context, arg *GetDocumentUploadCurrentPartParams) (*GetDocumentUploadCurrentPartRow, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentUploadCurrentPart, arg.Clientid, arg.Querydate)
|
|
var i GetDocumentUploadCurrentPartRow
|
|
err := row.Scan(&i.Part, &i.Count)
|
|
return &i, err
|
|
}
|
|
|
|
const listDocumentIDsBatch = `-- name: ListDocumentIDsBatch :many
|
|
SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
|
`
|
|
|
|
type ListDocumentIDsBatchParams struct {
|
|
Clientid string `db:"clientid"`
|
|
Batchsize int32 `db:"batchsize"`
|
|
Pageoffset int32 `db:"pageoffset"`
|
|
}
|
|
|
|
type ListDocumentIDsBatchRow struct {
|
|
ID *uuid.UUID `db:"id"`
|
|
Totalcount *int64 `db:"totalcount"`
|
|
}
|
|
|
|
// ListDocumentIDsBatch
|
|
//
|
|
// SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
|
func (q *Queries) ListDocumentIDsBatch(ctx context.Context, arg *ListDocumentIDsBatchParams) ([]*ListDocumentIDsBatchRow, error) {
|
|
rows, err := q.db.Query(ctx, listDocumentIDsBatch, arg.Clientid, arg.Batchsize, arg.Pageoffset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListDocumentIDsBatchRow{}
|
|
for rows.Next() {
|
|
var i ListDocumentIDsBatchRow
|
|
if err := rows.Scan(&i.ID, &i.Totalcount); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listDocumentUploads = `-- name: ListDocumentUploads :many
|
|
SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id, folder_id FROM documentUploads WHERE clientId = $1 ORDER BY createdAt
|
|
`
|
|
|
|
type ListDocumentUploadsRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Clientid string `db:"clientid"`
|
|
Bucket string `db:"bucket"`
|
|
Key string `db:"key"`
|
|
Part uint16 `db:"part"`
|
|
Createdat pgtype.Timestamp `db:"createdat"`
|
|
Filename *string `db:"filename"`
|
|
BatchID *uuid.UUID `db:"batch_id"`
|
|
FolderID *uuid.UUID `db:"folder_id"`
|
|
}
|
|
|
|
// ListDocumentUploads
|
|
//
|
|
// SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id, folder_id FROM documentUploads WHERE clientId = $1 ORDER BY createdAt
|
|
func (q *Queries) ListDocumentUploads(ctx context.Context, clientid string) ([]*ListDocumentUploadsRow, error) {
|
|
rows, err := q.db.Query(ctx, listDocumentUploads, clientid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListDocumentUploadsRow{}
|
|
for rows.Next() {
|
|
var i ListDocumentUploadsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Clientid,
|
|
&i.Bucket,
|
|
&i.Key,
|
|
&i.Part,
|
|
&i.Createdat,
|
|
&i.Filename,
|
|
&i.BatchID,
|
|
&i.FolderID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listDocumentsByBatch = `-- name: ListDocumentsByBatch :many
|
|
SELECT id, hash, filename from documents where batch_id = $1
|
|
`
|
|
|
|
type ListDocumentsByBatchRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Hash string `db:"hash"`
|
|
Filename *string `db:"filename"`
|
|
}
|
|
|
|
// ListDocumentsByBatch
|
|
//
|
|
// SELECT id, hash, filename from documents where batch_id = $1
|
|
func (q *Queries) ListDocumentsByBatch(ctx context.Context, batchID *uuid.UUID) ([]*ListDocumentsByBatchRow, error) {
|
|
rows, err := q.db.Query(ctx, listDocumentsByBatch, batchID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListDocumentsByBatchRow{}
|
|
for rows.Next() {
|
|
var i ListDocumentsByBatchRow
|
|
if err := rows.Scan(&i.ID, &i.Hash, &i.Filename); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listDocumentsByClient = `-- name: ListDocumentsByClient :many
|
|
SELECT id, hash from documents where clientId = $1
|
|
`
|
|
|
|
type ListDocumentsByClientRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Hash string `db:"hash"`
|
|
}
|
|
|
|
// ListDocumentsByClient
|
|
//
|
|
// SELECT id, hash from documents where clientId = $1
|
|
func (q *Queries) ListDocumentsByClient(ctx context.Context, clientid string) ([]*ListDocumentsByClientRow, error) {
|
|
rows, err := q.db.Query(ctx, listDocumentsByClient, clientid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListDocumentsByClientRow{}
|
|
for rows.Next() {
|
|
var i ListDocumentsByClientRow
|
|
if err := rows.Scan(&i.ID, &i.Hash); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|