From 655984115b5834173eef0297440f3071df33ecd0 Mon Sep 17 00:00:00 2001 From: andres Date: Mon, 8 Jul 2024 00:15:27 +0200 Subject: [PATCH] add raw query endpoint --- api/src/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/src/index.ts b/api/src/index.ts index 996efe1..5a7beb5 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -1,5 +1,5 @@ import cors from "@elysiajs/cors"; -import { Elysia } from "elysia"; +import { Elysia, t } from "elysia"; import postgres from "postgres"; const DB_URL = Bun.env.DB_URL; @@ -70,6 +70,19 @@ const app = new Elysia({ prefix: "/api" }) return new Response(JSON.stringify(foreignKeys, null, 2)).json(); }, ) + .post( + "raw", + async ({ body }) => { + const { query } = body; + const result = await sql.unsafe(query); + return new Response(JSON.stringify(result, null, 2)).json(); + }, + { + body: t.Object({ + query: t.String(), + }), + }, + ) .use(cors()) .listen(3000);