function promisifyBuilder(builder)
{  
  return new Promise((resolve, reject) => {

    try{

      builder.callback(function(err, response) {

        if(err != null) reject(err);
        resolve(response);
      });   

    } catch (error) {
      reject(error);
    }
  })
}

function makeMapFromDbResult(response, ...keys)
{
  let s = "-";
  let data = {};
  
  for(let i = 0; i < response.length; i++)
  {
    let record = response[i];

    let k = [];
    for(let j = 0; j < keys.length; j++)
    {
      k.push( record[keys[j]] );
    }

    let key = k.join(s);
    data[ key ] = record;
  }

  return data;
}

module.exports = {
    promisifyBuilder,
    makeMapFromDbResult
  }