text: const router = require("express").Router();
  const { pool } = require("../config");
  
  router.post("/", async (req, res) => {
    try {
      const { spor_adi, aciklama } = req.body;
      const result = await pool.query(
        `INSERT INTO spor("spor_adi","aciklama") VALUES($1,$2)`,
        [spor_adi, aciklama]
      );
    } catch (error) {
      console.log(error);
    }
  });
  
  router.get("/", async (req, res) => {
    try {
      const result = await pool.query(`SELECT * FROM spor WHERE "spor"."spor_id"!=0;`);
      const sporlar = result.rows;
  
      res.json({ sporlar });
    } catch (error) {
      console.log(error);
    }
  });
  
  router.get("/:id", async (req, res) => {
    try {
      const { id } = req.params;
      const result = await pool.query(
        `SELECT * FROM spor WHERE "spor"."spor_id"=${id} AND "spor"."spor_id"!=0;`
      );
      const spor = result.rows[0];
  
      res.json({ spor });
    } catch (error) {
      console.log(error);
    }
  });
  
  router.put("/:id", async (req, res) => {
    try {
      const { id } = req.params;
      const intId = parseInt(id);
      const { spor_adi, aciklama } = req.body;
      const result = await pool.query(`UPDATE "spor" SET "spor_adi" = '${spor_adi}', "aciklama" = '${aciklama}' 
    WHERE "spor_id" = ${intId};`);
  
      res.status(200).json({ success: true });
    } catch (error) {
      console.log(error);
    }
  });
  router.delete("/:id", async (req, res) => {
    try {
      const { id } = req.params;
      const intId = parseInt(id);
      const result = await pool.query(
        `DELETE FROM "spor" WHERE "spor_id" = ${intId};`
      );
  
      res.status(200).json({ success: true });
    } catch (error) {
      console.log(error);
    }
  });
  module.exports = router;
  