import { connection } from "@/lib/duckdb";
import type { NextApiRequest, NextApiResponse } from "next";

export default async function handler(
    req: NextApiRequest,
    res: NextApiResponse,
) {
    try {
        const result = await connection.run(`
            SELECT post_name, post_type 
            FROM wp_posts
            WHERE post_status = 'publish' 
            AND post_type IN ('post', 'page')
            ORDER BY post_date DESC;
        `);
        const rows = await result.getRowObjectsJson();
        res.status(200).json(rows);
    } catch (error) {
        console.error('Error fetching slugs:', error);
        res.status(500).json({ error: 'Failed to fetch slugs' });
    }
}