// 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 ), 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 } 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 }