53ea7d34e6
Start adding Textract + UUID changes * base * startclient * ts * short * tests
257 lines
6.8 KiB
Go
257 lines
6.8 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"
|
|
)
|
|
|
|
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 createDocument = `-- name: CreateDocument :one
|
|
INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
|
|
`
|
|
|
|
type CreateDocumentParams struct {
|
|
Clientid uuid.UUID `db:"clientid"`
|
|
Hash string `db:"hash"`
|
|
}
|
|
|
|
// CreateDocument
|
|
//
|
|
// INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
|
|
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (uuid.UUID, error) {
|
|
row := q.db.QueryRow(ctx, createDocument, arg.Clientid, arg.Hash)
|
|
var id uuid.UUID
|
|
err := row.Scan(&id)
|
|
return id, 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,
|
|
c.externalId AS clientId,
|
|
d.hash,
|
|
COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
|
|
FROM docs AS d
|
|
JOIN clients AS c ON c.id = d.clientId
|
|
LEFT JOIN namedResults AS r ON d.id = r.id
|
|
GROUP BY d.id, c.externalId, 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,
|
|
// c.externalId AS clientId,
|
|
// d.hash,
|
|
// COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
|
|
// FROM docs AS d
|
|
// JOIN clients AS c ON c.id = d.clientId
|
|
// LEFT JOIN namedResults AS r ON d.id = r.id
|
|
// GROUP BY d.id, c.externalId, 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 uuid.UUID `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
|
|
`
|
|
|
|
// GetDocumentSummary
|
|
//
|
|
// SELECT id, clientId, hash FROM documents WHERE id = $1
|
|
func (q *Queries) GetDocumentSummary(ctx context.Context, id uuid.UUID) (*Document, error) {
|
|
row := q.db.QueryRow(ctx, getDocumentSummary, id)
|
|
var i Document
|
|
err := row.Scan(&i.ID, &i.Clientid, &i.Hash)
|
|
return &i, err
|
|
}
|
|
|
|
const listDocumentIDsBatch = `-- name: ListDocumentIDsBatch :many
|
|
SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
|
`
|
|
|
|
type ListDocumentIDsBatchParams struct {
|
|
Clientid uuid.UUID `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 listDocumentsByClientExternalId = `-- name: ListDocumentsByClientExternalId :many
|
|
WITH client as (
|
|
SELECT id from clients where externalId = $1
|
|
)
|
|
SELECT d.id, d.hash
|
|
from documents as d
|
|
JOIN client as c on d.clientId = c.id
|
|
`
|
|
|
|
type ListDocumentsByClientExternalIdRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Hash string `db:"hash"`
|
|
}
|
|
|
|
// ListDocumentsByClientExternalId
|
|
//
|
|
// WITH client as (
|
|
// SELECT id from clients where externalId = $1
|
|
// )
|
|
// SELECT d.id, d.hash
|
|
// from documents as d
|
|
// JOIN client as c on d.clientId = c.id
|
|
func (q *Queries) ListDocumentsByClientExternalId(ctx context.Context, clientid string) ([]*ListDocumentsByClientExternalIdRow, error) {
|
|
rows, err := q.db.Query(ctx, listDocumentsByClientExternalId, clientid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListDocumentsByClientExternalIdRow{}
|
|
for rows.Next() {
|
|
var i ListDocumentsByClientExternalIdRow
|
|
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
|
|
}
|