Test to access student DB in other apps (working)

This commit is contained in:
Clayzxr
2025-01-22 11:35:47 +01:00
parent d767cb0898
commit 36c5c9cf39
6 changed files with 134 additions and 6 deletions
@@ -0,0 +1,31 @@
import { Handlers } from "$fresh/server.ts";
import connect from "$root/databases/connect.ts";
export const handler: Handlers = {
async GET() {
try {
using connection = connect("students");
const promotions = connection.database.prepare(
"select id from promotions",
).all();
const students = connection.database
.prepare(
`select userId, firstName, lastName, mail, promotionId from students`,
)
.all();
return new Response(
JSON.stringify({ promotions, students }),
{
status: 200,
headers: { "Content-Type": "application/json" },
},
);
} catch (error) {
console.error("Error fetching data:", error);
return new Response("Failed to fetch data", { status: 500 });
}
},
};