const { database } = require('../database.backup');

const createConfigIp = (ipname) => {
  const query = database.prepare('INSERT INTO ipconfig (ipname) VALUES (?)');

  try {
    let response = query.run(ipname)

    return response;
  } catch (error) {
    return error;
  }
}

const getIPConfig = async () => {
  try {
    let response = await database.prepare('SELECT * FROM ipconfig WHERE id = ?').get(1);

    return response;
  } catch (error) {
    return error
  }
}

const updateIPConfig = async (id, name) => {
  let query = database.prepare('UPDATE ipconfig SET ipname = ? WHERE id = ?');

  try {
    let response = await query.run(name, id);

    return response;
  } catch (error) {
    return error;
  }
}

module.exports = {
  createConfigIp,
  getIPConfig,
  updateIPConfig
}
