title: Is there any method to insert a row with pad a number with leading zeros in NodeJS-MySQL?
body: <p>I'm doing a NodeJs-Angular project and I want to register a user with custom auto increment id in MySQL table(like BM-0000118,MG-0000119). So after checking the user register or not, I started to insert a query with non-primary column value, then get the last inserted value using "results. inserted" and customized it with the paddy function (this function is in the below code). finally, update the row with customized id and another variable. It's working fine as I want. But I'm not sure about this method. Is there any best way to do this?</p>
  
  <p><a href="https://i.stack.imgur.com/QqWQA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QqWQA.png" alt="enter image description here"></a></p>
  
  <pre><code>       chirprdb.addCustomer = (uname,nic,email,phone,gender,dob,civilStatus,district,area,address,status) =&gt;{
      return new Promise((resolve, reject)=&gt;{
          pool.query('SELECT COUNT(*) AS count FROM customers WHERE nic = ? ',[nic],(err,results)=&gt;{
              if (err) {
                  return reject(err)
              }else if (results[0].count &gt; 0) {
                  ss = "Already register customer!";
                  return reject(ss);
              } else{
                  pool.query('INSERT INTO customers (district) VALUES (?) ',[district],(err,results)=&gt;{
                      if (err) {
                          ss = "sOMTHING WRONG";
                          return reject(err);
                      }
                      function paddy(num, padlen, padchar) {
                          var pad_char = typeof padchar !== 'undefined' ? padchar : '0';
                          var pad = new Array(1 + padlen).join(pad_char);
                          return (pad + num).slice(-pad.length);
                      }
                      const inserted_id = results.insertId;
                      var fu = paddy(inserted_id, 8);
  
                      const new_id = area+"-"+fu;
  
                      pool.query('UPDATE customers SET  cid = ?,uname = ?,nic = ?,email = ?,phone = ?,gender = ?,dob = ?,civilStatus = ?,district = ?,area = ?, address = ?,status = ? WHERE id = '+inserted_id+' ',[new_id,uname,nic,email,phone,gender,dob,civilStatus,district,area,address,status],(err,results)=&gt;{
                          if(err){
                              return reject(err);
                          }
                          return resolve(results)                
                      });                  
                  });
              }
          });
      });
  };
  </code></pre>