You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1009 B
32 lines
1009 B
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
import { OkPacket, QueryError, RowDataPacket } from "mysql2";
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
var pool = require("../../server/db/connect");
|
|
|
|
type Data = {
|
|
row: string,
|
|
}
|
|
|
|
const queryString = "SELECT name, types FROM product_categories WHERE status=1";
|
|
|
|
export default function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse<Data>)
|
|
{
|
|
pool.getConnection(function(err: QueryError, rows: RowDataPacket[0]){
|
|
if (err) {
|
|
rows.release();
|
|
throw err;
|
|
}
|
|
rows.query(queryString,function(err: QueryError, rows: RowDataPacket[0]){
|
|
// rows.release();
|
|
if(!err) {
|
|
res.status(200).json(rows);
|
|
}
|
|
});
|
|
rows.on('error', function(err: QueryError,) {
|
|
throw err;
|
|
return;
|
|
});
|
|
});
|
|
}; |