You are going to write the invoice.js API route for our invoice viewer app.

Click here to see the file you'll edit.

This is a Fastify app but that shouldn't really matter. You should really only need to write SQLite code.

All of the frontend and Fastify code should just work with no need for you to modify it, but feel free to. It's written in HTMX.

This doesn't need to be the most optimized code. You can nest callbacks if you want to, you can make multiple queries, or you can try to optimize the hell out of it.

I installed sqlite3 for you already, but if you're so inclined, feel free to use other SQLite libraries.

The point here is to learn and experiment.

The version I wrote (which is definitely not the optimal solution) is here.