Files
query-orchestration/internal/database/repository/document.sql.go
T

208 lines
5.8 KiB
Go
Raw Normal View History

2025-01-23 14:56:20 +00:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: document.sql
package repository
import (
"context"
"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 pgtype.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
}
2025-01-23 14:56:20 +00:00
const createDocument = `-- name: CreateDocument :one
INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
2025-01-23 14:56:20 +00:00
`
type CreateDocumentParams struct {
Clientid pgtype.UUID `db:"clientid"`
Hash string `db:"hash"`
}
2025-01-23 14:56:20 +00:00
// CreateDocument
//
// INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, createDocument, arg.Clientid, arg.Hash)
2025-01-23 14:56:20 +00:00
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const getDocument = `-- name: GetDocument :one
SELECT id, clientId, hash FROM documents WHERE id = $1 LIMIT 1
2025-01-23 14:56:20 +00:00
`
// GetDocument
//
// SELECT id, clientId, hash FROM documents WHERE id = $1 LIMIT 1
2025-01-23 14:56:20 +00:00
func (q *Queries) GetDocument(ctx context.Context, id pgtype.UUID) (*Document, error) {
row := q.db.QueryRow(ctx, getDocument, id)
var i Document
err := row.Scan(&i.ID, &i.Clientid, &i.Hash)
2025-01-23 14:56:20 +00:00
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 pgtype.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 pgtype.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 getDocumentIDByHash = `-- name: GetDocumentIDByHash :one
SELECT id FROM documents WHERE hash = $1 and clientId = $2
`
type GetDocumentIDByHashParams struct {
Hash string `db:"hash"`
Clientid pgtype.UUID `db:"clientid"`
}
// GetDocumentIDByHash
//
// SELECT id FROM documents WHERE hash = $1 and clientId = $2
func (q *Queries) GetDocumentIDByHash(ctx context.Context, arg *GetDocumentIDByHashParams) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, getDocumentIDByHash, arg.Hash, arg.Clientid)
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const listDocumentIDsBatch = `-- name: ListDocumentIDsBatch :many
SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
`
type ListDocumentIDsBatchParams struct {
Clientid pgtype.UUID `db:"clientid"`
Batchsize int32 `db:"batchsize"`
Pageoffset int32 `db:"pageoffset"`
}
type ListDocumentIDsBatchRow struct {
ID pgtype.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
),
docs as (
SELECT d.id
from documents as d
JOIN client as c on d.clientId = c.id
),
entries as (
SELECT
de.documentId,
de.bucket,
de.key,
ROW_NUMBER() OVER (PARTITION BY de.documentId ORDER BY de.id DESC) as rowNumber
FROM docs d
JOIN documentEntries de on d.id = de.documentId
)
SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1
`
type ListDocumentsByClientExternalIdRow struct {
ID pgtype.UUID `db:"id"`
Bucket string `db:"bucket"`
Key string `db:"key"`
}
// ListDocumentsByClientExternalId
//
// WITH client as (
// SELECT id from clients where externalId = $1
// ),
// docs as (
// SELECT d.id
// from documents as d
// JOIN client as c on d.clientId = c.id
// ),
// entries as (
// SELECT
// de.documentId,
// de.bucket,
// de.key,
// ROW_NUMBER() OVER (PARTITION BY de.documentId ORDER BY de.id DESC) as rowNumber
// FROM docs d
// JOIN documentEntries de on d.id = de.documentId
// )
// SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1
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.Bucket, &i.Key); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}