81e7223560
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
245 lines
6.4 KiB
Go
245 lines
6.4 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 string `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,
|
|
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
|
|
`
|
|
|
|
// 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 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 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
|
|
}
|