// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: opportunity_records.sql package dbgen import ( "context" "time" "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" "github.com/shopspring/decimal" ) const getOpportunityRecord = `-- name: GetOpportunityRecord :one SELECT id, source_name, source_record_id, dedupe_key, record_kind, title, agency, sub_agency, naics, psc, pop_city, pop_state, pop_country, pop_zip, set_aside, set_aside_code, contract_vehicle, estimated_value, value_source, incumbent_name, incumbent_uei, posted_date, response_deadline, award_date, estimated_award_date, pop_start_date, pop_end_date, ui_link, is_planning, raw_object_key, raw_sha256, fetched_at, synced_at FROM opportunity_records WHERE id = $1 ` func (q *Queries) GetOpportunityRecord(ctx context.Context, id uuid.UUID) (OpportunityRecord, error) { row := q.db.QueryRow(ctx, getOpportunityRecord, id) var i OpportunityRecord err := row.Scan( &i.ID, &i.SourceName, &i.SourceRecordID, &i.DedupeKey, &i.RecordKind, &i.Title, &i.Agency, &i.SubAgency, &i.Naics, &i.Psc, &i.PopCity, &i.PopState, &i.PopCountry, &i.PopZip, &i.SetAside, &i.SetAsideCode, &i.ContractVehicle, &i.EstimatedValue, &i.ValueSource, &i.IncumbentName, &i.IncumbentUei, &i.PostedDate, &i.ResponseDeadline, &i.AwardDate, &i.EstimatedAwardDate, &i.PopStartDate, &i.PopEndDate, &i.UiLink, &i.IsPlanning, &i.RawObjectKey, &i.RawSha256, &i.FetchedAt, &i.SyncedAt, ) return i, err } const listOpportunityRecords = `-- name: ListOpportunityRecords :many SELECT id, source_name, source_record_id, dedupe_key, record_kind, title, agency, sub_agency, naics, psc, pop_city, pop_state, pop_country, pop_zip, set_aside, set_aside_code, contract_vehicle, estimated_value, value_source, incumbent_name, incumbent_uei, posted_date, response_deadline, award_date, estimated_award_date, pop_start_date, pop_end_date, ui_link, is_planning, raw_object_key, raw_sha256, fetched_at, synced_at FROM opportunity_records WHERE ($1::text[] IS NULL OR record_kind = ANY($1::text[])) AND ($2::text[] IS NULL OR naics = ANY($2::text[])) AND ($3::text[] IS NULL OR upper(agency) = ANY($3::text[])) AND ($4::text[] IS NULL OR upper(pop_state) = ANY($4::text[])) ORDER BY (response_deadline IS NULL OR response_deadline < now()), response_deadline ASC, posted_date DESC NULLS LAST, id LIMIT $5::int ` type ListOpportunityRecordsParams struct { Kinds []string `json:"kinds"` Naics []string `json:"naics"` Agencies []string `json:"agencies"` States []string `json:"states"` Lim int32 `json:"lim"` } // Optional filters (NULL array = no filter). Soonest closing first, then most recently posted, then id // as a unique tiebreaker so the order is deterministic. Text equality filters compare upper() on both // sides; the service upper cases the params so casing drift cannot silently zero out results. func (q *Queries) ListOpportunityRecords(ctx context.Context, arg ListOpportunityRecordsParams) ([]OpportunityRecord, error) { rows, err := q.db.Query(ctx, listOpportunityRecords, arg.Kinds, arg.Naics, arg.Agencies, arg.States, arg.Lim, ) if err != nil { return nil, err } defer rows.Close() items := []OpportunityRecord{} for rows.Next() { var i OpportunityRecord if err := rows.Scan( &i.ID, &i.SourceName, &i.SourceRecordID, &i.DedupeKey, &i.RecordKind, &i.Title, &i.Agency, &i.SubAgency, &i.Naics, &i.Psc, &i.PopCity, &i.PopState, &i.PopCountry, &i.PopZip, &i.SetAside, &i.SetAsideCode, &i.ContractVehicle, &i.EstimatedValue, &i.ValueSource, &i.IncumbentName, &i.IncumbentUei, &i.PostedDate, &i.ResponseDeadline, &i.AwardDate, &i.EstimatedAwardDate, &i.PopStartDate, &i.PopEndDate, &i.UiLink, &i.IsPlanning, &i.RawObjectKey, &i.RawSha256, &i.FetchedAt, &i.SyncedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const opportunityRecordMeta = `-- name: OpportunityRecordMeta :one SELECT COUNT(*)::bigint AS total, MAX(synced_at) AS last_synced FROM opportunity_records ` type OpportunityRecordMetaRow struct { Total int64 `json:"total"` LastSynced interface{} `json:"last_synced"` } func (q *Queries) OpportunityRecordMeta(ctx context.Context) (OpportunityRecordMetaRow, error) { row := q.db.QueryRow(ctx, opportunityRecordMeta) var i OpportunityRecordMetaRow err := row.Scan(&i.Total, &i.LastSynced) return i, err } const upsertOpportunityRecord = `-- name: UpsertOpportunityRecord :exec INSERT INTO opportunity_records ( source_name, source_record_id, dedupe_key, record_kind, title, agency, sub_agency, naics, psc, pop_city, pop_state, pop_country, pop_zip, set_aside, set_aside_code, contract_vehicle, estimated_value, value_source, incumbent_name, incumbent_uei, posted_date, response_deadline, award_date, estimated_award_date, pop_start_date, pop_end_date, ui_link, is_planning, raw_object_key, raw_sha256, fetched_at, synced_at ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, now() ) ON CONFLICT (source_name, source_record_id) DO UPDATE SET dedupe_key = EXCLUDED.dedupe_key, record_kind = EXCLUDED.record_kind, title = EXCLUDED.title, agency = EXCLUDED.agency, sub_agency = EXCLUDED.sub_agency, naics = EXCLUDED.naics, psc = EXCLUDED.psc, pop_city = EXCLUDED.pop_city, pop_state = EXCLUDED.pop_state, pop_country = EXCLUDED.pop_country, pop_zip = EXCLUDED.pop_zip, set_aside = EXCLUDED.set_aside, set_aside_code = EXCLUDED.set_aside_code, contract_vehicle = EXCLUDED.contract_vehicle, estimated_value = EXCLUDED.estimated_value, value_source = EXCLUDED.value_source, incumbent_name = EXCLUDED.incumbent_name, incumbent_uei = EXCLUDED.incumbent_uei, posted_date = EXCLUDED.posted_date, response_deadline = EXCLUDED.response_deadline, award_date = EXCLUDED.award_date, estimated_award_date = EXCLUDED.estimated_award_date, pop_start_date = EXCLUDED.pop_start_date, pop_end_date = EXCLUDED.pop_end_date, ui_link = EXCLUDED.ui_link, is_planning = EXCLUDED.is_planning, raw_object_key = EXCLUDED.raw_object_key, raw_sha256 = EXCLUDED.raw_sha256, fetched_at = EXCLUDED.fetched_at, synced_at = now() ` type UpsertOpportunityRecordParams struct { SourceName string `json:"source_name"` SourceRecordID string `json:"source_record_id"` DedupeKey string `json:"dedupe_key"` RecordKind string `json:"record_kind"` Title string `json:"title"` Agency string `json:"agency"` SubAgency string `json:"sub_agency"` Naics string `json:"naics"` Psc string `json:"psc"` PopCity string `json:"pop_city"` PopState string `json:"pop_state"` PopCountry string `json:"pop_country"` PopZip string `json:"pop_zip"` SetAside string `json:"set_aside"` SetAsideCode string `json:"set_aside_code"` ContractVehicle string `json:"contract_vehicle"` EstimatedValue *decimal.Decimal `json:"estimated_value"` ValueSource string `json:"value_source"` IncumbentName string `json:"incumbent_name"` IncumbentUei string `json:"incumbent_uei"` PostedDate pgtype.Date `json:"posted_date"` ResponseDeadline *time.Time `json:"response_deadline"` AwardDate pgtype.Date `json:"award_date"` EstimatedAwardDate pgtype.Date `json:"estimated_award_date"` PopStartDate pgtype.Date `json:"pop_start_date"` PopEndDate pgtype.Date `json:"pop_end_date"` UiLink string `json:"ui_link"` IsPlanning bool `json:"is_planning"` RawObjectKey string `json:"raw_object_key"` RawSha256 string `json:"raw_sha256"` FetchedAt time.Time `json:"fetched_at"` } // Opportunity Intelligence unified records. Global public catalog (no organization_id, outside RLS): // reads run straight off the pool, writes come from cmd/opp-sync as the migrator role. func (q *Queries) UpsertOpportunityRecord(ctx context.Context, arg UpsertOpportunityRecordParams) error { _, err := q.db.Exec(ctx, upsertOpportunityRecord, arg.SourceName, arg.SourceRecordID, arg.DedupeKey, arg.RecordKind, arg.Title, arg.Agency, arg.SubAgency, arg.Naics, arg.Psc, arg.PopCity, arg.PopState, arg.PopCountry, arg.PopZip, arg.SetAside, arg.SetAsideCode, arg.ContractVehicle, arg.EstimatedValue, arg.ValueSource, arg.IncumbentName, arg.IncumbentUei, arg.PostedDate, arg.ResponseDeadline, arg.AwardDate, arg.EstimatedAwardDate, arg.PopStartDate, arg.PopEndDate, arg.UiLink, arg.IsPlanning, arg.RawObjectKey, arg.RawSha256, arg.FetchedAt, ) return err }