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

201 lines
5.3 KiB
Go
Raw Normal View History

2025-01-21 18:24:14 +00:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: client.sql
package repository
import (
"context"
)
const addClientCanSync = `-- name: AddClientCanSync :exec
INSERT INTO clientCanSync (canSync, clientId) VALUES ($1, $2)
`
type AddClientCanSyncParams struct {
Cansync bool `db:"cansync"`
Clientid string `db:"clientid"`
}
// AddClientCanSync
//
// INSERT INTO clientCanSync (canSync, clientId) VALUES ($1, $2)
func (q *Queries) AddClientCanSync(ctx context.Context, arg *AddClientCanSyncParams) error {
_, err := q.db.Exec(ctx, addClientCanSync, arg.Cansync, arg.Clientid)
return err
}
const createClient = `-- name: CreateClient :exec
INSERT INTO clients (clientId, name) VALUES ($1, $2)
2025-01-21 18:24:14 +00:00
`
type CreateClientParams struct {
Clientid string `db:"clientid"`
Name string `db:"name"`
}
2025-01-21 18:24:14 +00:00
// CreateClient
//
// INSERT INTO clients (clientId, name) VALUES ($1, $2)
func (q *Queries) CreateClient(ctx context.Context, arg *CreateClientParams) error {
_, err := q.db.Exec(ctx, createClient, arg.Clientid, arg.Name)
return err
2025-01-21 18:24:14 +00:00
}
const getClient = `-- name: GetClient :one
SELECT clientid, name, cansync FROM fullClients WHERE clientId = $1
2025-01-21 18:24:14 +00:00
`
// GetClient
//
// SELECT clientid, name, cansync FROM fullClients WHERE clientId = $1
func (q *Queries) GetClient(ctx context.Context, clientid string) (*Fullclient, error) {
row := q.db.QueryRow(ctx, getClient, clientid)
var i Fullclient
err := row.Scan(&i.Clientid, &i.Name, &i.Cansync)
2025-01-21 18:24:14 +00:00
return &i, err
}
const isClientSynced = `-- name: IsClientSynced :one
WITH
docs AS (
-- Get all documents for this client
SELECT id, clientId FROM documents WHERE clientId = $1
),
doc_clean_entries as (
-- Documents with their current clean entries
SELECT
d.id AS document_id,
d.clientId as client_id,
cte.id AS clean_entry_id,
cte.fail as clean_fail
FROM
docs d
LEFT JOIN currentCleanEntries cte ON cte.documentId = d.id
),
doc_text_entries AS (
-- Documents with their current text entries
SELECT
d.document_id,
cte.id AS text_entry_id,
d.clean_entry_id,
d.clean_fail,
d.client_id
FROM
doc_clean_entries d
LEFT JOIN currentTextEntries cte ON cte.cleanId = d.clean_entry_id
)
SELECT (
-- No documents means client is synced
NOT EXISTS (SELECT 1 FROM docs)
OR
-- All documents have completed processing (clean entry exists and either
-- text entry exists or clean failed)
NOT EXISTS (
SELECT 1 FROM doc_text_entries
where clean_entry_id is null or
(clean_fail is null and text_entry_id is null)
)
)::bool as is_synced
`
// Query functionality has been removed. A client is considered synced when
// all documents have completed text extraction (or failed with explicit failure).
// See remove_query_plan.md for details.
//
// WITH
// docs AS (
// -- Get all documents for this client
// SELECT id, clientId FROM documents WHERE clientId = $1
// ),
// doc_clean_entries as (
// -- Documents with their current clean entries
// SELECT
// d.id AS document_id,
// d.clientId as client_id,
// cte.id AS clean_entry_id,
// cte.fail as clean_fail
// FROM
// docs d
// LEFT JOIN currentCleanEntries cte ON cte.documentId = d.id
// ),
// doc_text_entries AS (
// -- Documents with their current text entries
// SELECT
// d.document_id,
// cte.id AS text_entry_id,
// d.clean_entry_id,
// d.clean_fail,
// d.client_id
// FROM
// doc_clean_entries d
// LEFT JOIN currentTextEntries cte ON cte.cleanId = d.clean_entry_id
// )
// SELECT (
// -- No documents means client is synced
// NOT EXISTS (SELECT 1 FROM docs)
//
// OR
//
// -- All documents have completed processing (clean entry exists and either
// -- text entry exists or clean failed)
// NOT EXISTS (
// SELECT 1 FROM doc_text_entries
// where clean_entry_id is null or
// (clean_fail is null and text_entry_id is null)
// )
// )::bool as is_synced
func (q *Queries) IsClientSynced(ctx context.Context, dollar_1 *string) (bool, error) {
row := q.db.QueryRow(ctx, isClientSynced, dollar_1)
var is_synced bool
err := row.Scan(&is_synced)
return is_synced, err
}
const listClients = `-- name: ListClients :many
SELECT clientid, name, cansync FROM fullClients ORDER BY name
`
// Returns all clients ordered by name
//
// SELECT clientid, name, cansync FROM fullClients ORDER BY name
func (q *Queries) ListClients(ctx context.Context) ([]*Fullclient, error) {
rows, err := q.db.Query(ctx, listClients)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*Fullclient{}
for rows.Next() {
var i Fullclient
if err := rows.Scan(&i.Clientid, &i.Name, &i.Cansync); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
2025-01-21 18:24:14 +00:00
const updateClient = `-- name: UpdateClient :exec
UPDATE clients SET name = $1 WHERE clientId = $2
2025-01-21 18:24:14 +00:00
`
type UpdateClientParams struct {
Name string `db:"name"`
Clientid string `db:"clientid"`
2025-01-21 18:24:14 +00:00
}
// UpdateClient
//
// UPDATE clients SET name = $1 WHERE clientId = $2
2025-01-21 18:24:14 +00:00
func (q *Queries) UpdateClient(ctx context.Context, arg *UpdateClientParams) error {
_, err := q.db.Exec(ctx, updateClient, arg.Name, arg.Clientid)
2025-01-21 18:24:14 +00:00
return err
}