package repository import ( "context" "errors" "time" "github.com/google/uuid" "github.com/jackc/pgx/v5" ) // KnowledgeChunkRow is KnowledgeChunk catalog row. type KnowledgeChunkRow struct { ID uuid.UUID `json:"id"` Code string `json:"code"` SourceCode string `json:"source_code"` Title string `json:"title"` Body string `json:"body"` Active bool `json:"active"` System bool `json:"system"` UpdatedAt time.Time `json:"updated_at"` } // ListKnowledgeChunks returns KnowledgeChunk catalog. func (r *AdminRepo) ListKnowledgeChunks(ctx context.Context) ([]KnowledgeChunkRow, error) { rows, err := r.Pool.Query(ctx, ` SELECT id, code, source_code, title, body, active, system, updated_at FROM knowledge_chunks ORDER BY active DESC, code ASC LIMIT 500`) if err != nil { return nil, err } defer rows.Close() var out []KnowledgeChunkRow for rows.Next() { var row KnowledgeChunkRow if err := rows.Scan(&row.ID, &row.Code, &row.SourceCode, &row.Title, &row.Body, &row.Active, &row.System, &row.UpdatedAt); err != nil { return nil, err } out = append(out, row) } return out, rows.Err() } // GetKnowledgeChunk loads one by id. func (r *AdminRepo) GetKnowledgeChunk(ctx context.Context, id uuid.UUID) (*KnowledgeChunkRow, error) { var row KnowledgeChunkRow err := r.Pool.QueryRow(ctx, ` SELECT id, code, source_code, title, body, active, system, updated_at FROM knowledge_chunks WHERE id=$1`, id, ).Scan(&row.ID, &row.Code, &row.SourceCode, &row.Title, &row.Body, &row.Active, &row.System, &row.UpdatedAt) if errors.Is(err, pgx.ErrNoRows) { return nil, err } if err != nil { return nil, err } return &row, nil }