Files
query-orchestration/internal/database/repository/client.sql.go
T
Jay Brown 35d72fccbe Merged in feature/remove-mocks (pull request #202)
Feature/remove mocks

* remove mocks

* cleanup db migrations
2026-01-15 20:39:32 +00:00

173 lines
4.5 KiB
Go

// 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)
`
type CreateClientParams struct {
Clientid string `db:"clientid"`
Name string `db:"name"`
}
// 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
}
const getClient = `-- name: GetClient :one
SELECT clientid, name, cansync FROM fullClients WHERE clientId = $1
`
// 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)
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
)
SELECT (
-- No documents means client is synced
NOT EXISTS (SELECT 1 FROM docs)
OR
-- All documents have completed processing (clean entry exists OR clean failed)
NOT EXISTS (
SELECT 1 FROM doc_clean_entries
WHERE clean_entry_id IS NULL
)
)::bool as is_synced
`
// Text extraction has been removed. A client is considered synced when
// all documents have completed cleaning (clean entry exists OR clean failed).
// See remove_texttract_and_mocks_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
// )
// SELECT (
// -- No documents means client is synced
// NOT EXISTS (SELECT 1 FROM docs)
//
// OR
//
// -- All documents have completed processing (clean entry exists OR clean failed)
// NOT EXISTS (
// SELECT 1 FROM doc_clean_entries
// WHERE clean_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
}
const updateClient = `-- name: UpdateClient :exec
UPDATE clients SET name = $1 WHERE clientId = $2
`
type UpdateClientParams struct {
Name string `db:"name"`
Clientid string `db:"clientid"`
}
// UpdateClient
//
// UPDATE clients SET name = $1 WHERE clientId = $2
func (q *Queries) UpdateClient(ctx context.Context, arg *UpdateClientParams) error {
_, err := q.db.Exec(ctx, updateClient, arg.Name, arg.Clientid)
return err
}