Questions about how to efficiently use mysql pools with node.js

0

Reading the Documentation from mysql it offers the creation of pools, but it has a parameter called connectionLimit and mine doubt is on top of that! This limit that I will impose is in relation to:

  • How often will a query be done on that thread?
  • How many times will the query be based on the object being instantiated?
  • If it is based on the object, do I have to scale it if I have 100 or more queries at a time?
  • So what's my code:

    Controller:

    exports.post = async (req, res, next) => {
    const Email = req.body.Email;
    const Passw = req.body.Password;
    if(fluentValidation.validateEmail(Email) && fluentValidation.isValidLength(Passw)){
        try {        
          await sqlService.SignUpUser(Email,Passw,res,req);
        } catch (error) {
            console.log(error);
        }
    }else{
        res.status(400).send({
            Error : "Email invalid"
        });
       }   
    }
    

    And I created a class called SQLService where it connects and I export methods to make queries.

    const pool = sql.createPool ({
    connectionLimit : 10,
    host: '0.0.0.0',
    user:'foo',
    password : 'foo',
    database : 'foo'
    });
    
    
    module.exports.SignUpUser = async (email,password,res,req) =>{
    pool.getConnection(function(err,connection){
        if(err){
            console.log(err);
        }else{
            connection.query('select email from user where email = '${email}'', function (error, results, fields){
                if(results.length < 1){
                    let date = dateT.getdate();
                    let guid =  uuid();
                    let etoken = uuid();
                    connection.query('INSERT INTO e(e,e,e,e,e) VALUES ('${e}','${e}','${e}','${e}','${e}')', function (error, results, fields){
                        if(err){
                            console.log(err);
                        }else{
                            res.status(201).send();
                            emailService.send(req.body.Email,'Bem vindo ao e',url.buildUrl(req.headers.host,'/validate/'+ etoken));
                        }
                    })
                }else{
                    res.status(409).send();
                }
            });
            connection.release();
        }
      });
    }
    

    After I finish with the operation of this module that only has two queries connection.release(); , is this considered as two connections? I was a bit lost because I came from C # and using EntityFramework never had to worry about it! Thanks!

        
    asked by anonymous 01.10.2018 / 20:08

    0 answers