// 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 ), required_results AS ( -- All required document-query-version combinations SELECT dte.document_id, cqdt.queryId, cqdt.queryVersion, dte.text_entry_id FROM doc_text_entries dte JOIN collectorQueryDependencyTreeByClient($1) cqdt ON cqdt.clientId = dte.client_id where dte.clean_fail is null and dte.text_entry_id IS NOT NULL ), existing_results AS ( -- Valid results that exist SELECT rr.document_id AS document_id, r.queryId, r.id AS result_id FROM results r JOIN required_results rr ON r.queryId = rr.queryId AND r.queryVersion = rr.queryVersion AND r.textEntryId = rr.text_entry_id ), missing_results AS ( -- Find missing results SELECT rr.queryId FROM required_results rr LEFT JOIN existing_results er on er.queryId = rr.queryId WHERE er.result_id is null ), dependency_check AS ( -- Check for missing dependencies SELECT DISTINCT er.queryId, er.result_id, qcri.queryId, rd.resultId FROM existing_results er JOIN queryCurrentRequiredIds qcri on qcri.requiredQueryId = er.queryId LEFT JOIN resultDependencies rd on rd.requiredResultId = er.result_id WHERE rd.resultId is null ) SELECT ( -- No documents means client is synced NOT EXISTS (SELECT 1 FROM docs) OR -- Documents with no text entries ( 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) ) and -- Documents with missing results NOT EXISTS (SELECT 1 FROM missing_results) and -- Documents with missing dependencies NOT EXISTS (SELECT 1 FROM dependency_check) )::bool )::bool as is_synced ` // IsClientSynced // // 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 // ), // required_results AS ( // -- All required document-query-version combinations // SELECT // dte.document_id, // cqdt.queryId, // cqdt.queryVersion, // dte.text_entry_id // FROM // doc_text_entries dte // JOIN collectorQueryDependencyTreeByClient($1) cqdt ON cqdt.clientId = dte.client_id // where dte.clean_fail is null and dte.text_entry_id IS NOT NULL // ), // existing_results AS ( // -- Valid results that exist // SELECT // rr.document_id AS document_id, // r.queryId, // r.id AS result_id // FROM // results r // JOIN required_results rr ON // r.queryId = rr.queryId AND // r.queryVersion = rr.queryVersion AND // r.textEntryId = rr.text_entry_id // ), // missing_results AS ( // -- Find missing results // SELECT rr.queryId // FROM required_results rr // LEFT JOIN existing_results er on er.queryId = rr.queryId // WHERE er.result_id is null // ), // dependency_check AS ( // -- Check for missing dependencies // SELECT DISTINCT er.queryId, er.result_id, qcri.queryId, rd.resultId // FROM existing_results er // JOIN queryCurrentRequiredIds qcri on qcri.requiredQueryId = er.queryId // LEFT JOIN resultDependencies rd on rd.requiredResultId = er.result_id // WHERE rd.resultId is null // ) // SELECT ( // -- No documents means client is synced // NOT EXISTS (SELECT 1 FROM docs) // // OR // // -- Documents with no text entries // ( // 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) // ) // // and // // -- Documents with missing results // NOT EXISTS (SELECT 1 FROM missing_results) // // and // // -- Documents with missing dependencies // NOT EXISTS (SELECT 1 FROM dependency_check) // )::bool // )::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 }