generated from stegripe/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add API routes for retrieving DB data
- Loading branch information
mzrtamp
committed
Mar 6, 2024
1 parent
dee2d2f
commit e16b208
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import connection from "../../index"; | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async function columns( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const table = req.query["table"]; | ||
if (!table) { | ||
res.status(400).json({ message: "Ngawur cik, mana nama tablenya???" }); | ||
return; | ||
} | ||
|
||
const columns = await connection.query({ | ||
query: "SHOW COLUMNS FROM ?", | ||
values: [table] | ||
}); | ||
|
||
res.status(200).json(columns); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import connection from "../../index"; | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async function retrieveAll( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const table = req.query["table"]; | ||
if (!table) { | ||
res.status(400).json({ message: "Ngawur cik, mana nama tablenya???" }); | ||
return; | ||
} | ||
|
||
const datas = await connection.query({ | ||
query: "SELECT * FROM ?", | ||
values: [table] | ||
}); | ||
|
||
res.status(200).json(datas); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import connection from "../../index"; // ts server nya stress | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async function tables( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const query = await connection.query("SHOW TABLES"); | ||
res.status(200).json(query); | ||
} |