const mysql = require("mysql2/promise");

// create the connection to database
const db = mysql.createPool({
    host: 'localhost',
    user: 'bobros_7639236966',
    database: 'hweels',
    password: '1434@Humming',
  });



const getCities =  async (req, res) => {
  const namePrefix = req.query.name || '';

  try {
    const [rows] = await db.execute(
      'SELECT * FROM cities WHERE cityname LIKE ?',
      [`${namePrefix}%`]
    );
    res.json(rows);
  } catch (error) {
    //console.error('Error fetching cities:', error);
    res.status(500).json({ error: 'Something went wrong' });
  }
};



module.exports= {
    getCities
}