Files
Jay Brown 09c61ea9b4 Merged in feature/add-deletes (pull request #214)
support delete for client, document and folder

* support delete

for client, document and folder

* remove batch cancel conflict

not used


Approved-by: Jacob Mathison
2026-03-04 18:30:13 +00:00

309 lines
8.7 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: client.sql
package repository
import (
"context"
"github.com/google/uuid"
)
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 deleteAllFoldersForClient = `-- name: DeleteAllFoldersForClient :exec
DELETE FROM folders WHERE clientId = $1
`
// @sqlc-vet-disable
// Delete all folders for a client. All documents must already be deleted to avoid FK violations.
//
// DELETE FROM folders WHERE clientId = $1
func (q *Queries) DeleteAllFoldersForClient(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteAllFoldersForClient, clientID)
return err
}
const deleteBatchUploads = `-- name: DeleteBatchUploads :exec
DELETE FROM batch_uploads WHERE client_id = $1
`
// @sqlc-vet-disable
// Delete all batch upload records for a client
//
// DELETE FROM batch_uploads WHERE client_id = $1
func (q *Queries) DeleteBatchUploads(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteBatchUploads, clientID)
return err
}
const deleteClientCanSync = `-- name: DeleteClientCanSync :exec
DELETE FROM clientCanSync WHERE clientId = $1
`
// @sqlc-vet-disable
// Delete clientCanSync records for a client
//
// DELETE FROM clientCanSync WHERE clientId = $1
func (q *Queries) DeleteClientCanSync(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteClientCanSync, clientID)
return err
}
const deleteCollectorActiveVersions = `-- name: DeleteCollectorActiveVersions :exec
DELETE FROM collectorActiveVersions WHERE clientId = $1
`
// @sqlc-vet-disable
// Delete collector active version records for a client
//
// DELETE FROM collectorActiveVersions WHERE clientId = $1
func (q *Queries) DeleteCollectorActiveVersions(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteCollectorActiveVersions, clientID)
return err
}
const deleteCollectorMinCleanVersions = `-- name: DeleteCollectorMinCleanVersions :exec
DELETE FROM collectorMinCleanVersions WHERE clientId = $1
`
// @sqlc-vet-disable
// Delete collector minimum clean version records for a client
//
// DELETE FROM collectorMinCleanVersions WHERE clientId = $1
func (q *Queries) DeleteCollectorMinCleanVersions(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteCollectorMinCleanVersions, clientID)
return err
}
const deleteCollectorVersions = `-- name: DeleteCollectorVersions :exec
DELETE FROM collectorVersions WHERE clientId = $1
`
// @sqlc-vet-disable
// Delete collector version records for a client
//
// DELETE FROM collectorVersions WHERE clientId = $1
func (q *Queries) DeleteCollectorVersions(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteCollectorVersions, clientID)
return err
}
const deleteDocumentUploadsForClient = `-- name: DeleteDocumentUploadsForClient :exec
DELETE FROM documentUploads WHERE clientId = $1
`
// @sqlc-vet-disable
// Delete all documentUploads for a client
//
// DELETE FROM documentUploads WHERE clientId = $1
func (q *Queries) DeleteDocumentUploadsForClient(ctx context.Context, clientID string) error {
_, err := q.db.Exec(ctx, deleteDocumentUploadsForClient, clientID)
return err
}
const getAllDocumentIDsForClient = `-- name: GetAllDocumentIDsForClient :many
SELECT id FROM documents WHERE clientId = $1
`
// Get all document IDs for a client, used to cascade document deletes during client delete
//
// SELECT id FROM documents WHERE clientId = $1
func (q *Queries) GetAllDocumentIDsForClient(ctx context.Context, clientID string) ([]uuid.UUID, error) {
rows, err := q.db.Query(ctx, getAllDocumentIDsForClient, clientID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []uuid.UUID{}
for rows.Next() {
var id uuid.UUID
if err := rows.Scan(&id); err != nil {
return nil, err
}
items = append(items, id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
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 hardDeleteClient = `-- name: HardDeleteClient :execrows
DELETE FROM clients WHERE clientId = $1
`
// @sqlc-vet-disable
// Hard delete the client row itself. Returns the number of rows deleted (0 or 1).
//
// DELETE FROM clients WHERE clientId = $1
func (q *Queries) HardDeleteClient(ctx context.Context, clientID string) (int64, error) {
result, err := q.db.Exec(ctx, hardDeleteClient, clientID)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
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
}