How to use the mysql.createPool function in mysql

To help you get started, we’ve selected a few mysql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github steven37788 / stock_dde / mysql_dde.js View on Github external
}


/**
 * 数据库模块
 */
var options = {
    host: 'localhost',
    user: 'root',
    password: 'Derman',
    database: 'nodejs',
    port: 3306
};


var pool = mysql.createPool(options);

///**
// * 释放数据库连接
// */
//exports.release = function(connection) {
//	connection.end(function(error) {
//		logger.info('Connection closed');
//	});
//};

/**
 * 执行查询
 */
function execQuery(options) {
    pool.getConnection(function(error, connection) {
github steven37788 / stock_dde / mysql_homepage.js View on Github external
return insertsql;
}

/**
 * 数据库模块
 */
var options = {
    host: 'localhost',
    user: 'root',
    password: 'Derman',
    database: 'nodejs',
    port: 3306
};

var mysql = require('mysql');
var pool = mysql.createPool(options);

///**
// * 释放数据库连接
// */
//exports.release = function(connection) {
//	connection.end(function(error) {
//		logger.info('Connection closed');
//	});
//};

/**
 * 执行查询
 */


function execQuery_homepage(options, cb) {
github mevdschee / js-crud-api / app.js View on Github external
var http = require("http");
var mysql = require("mysql");

// connect to the mysql database

var pool = mysql.createPool({
  connectionLimit: 100, //important
  host: 'localhost',
  user: 'php-crud-api',
  password: 'php-crud-api',
  database: 'php-crud-api',
  charset: 'utf8',
  debug: false
});

// ensure request has database connection

var withDb = function (handler) {
  return function (req, resp) {
    pool.getConnection(function (err, connection) {
      if (err) {
        resp.writeHead(404)
github mysql / mysql-js / jones-mysql / impl / MySQLConnectionPool.js View on Github external
} else {
      stats.connections.successful++;
      connectionPool.is_connected = true;
      connectionPool.releaseConnection(connection);
      callback(null, connectionPool);
    }
  }

  // connect begins here
  if (connectionPool.is_connected) {
    udebug.log('MySQLConnectionPool.connect is already connected');
    callback(null, connectionPool);
  } else {
    connectionPool.is_connecting = true;
    if (connectionPool.pooling) {
      connectionPool.pool = mysql.createPool(connectionPool.driverproperties);
    }
    // verify that the connection properties work by getting a connection
    connectionPool.getConnection(connectOnConnection);
  }
};
github alanszlosek / voxeling / src / lib / chunk-stores / mysql.js View on Github external
var MysqlChunkStore = function(generator, config) {
    var self = this;
    ChunkStore.call(this, generator);
    // ChunkID -> chunk data structure
    this.toSave = {};
    this.changes = {};
    this.mysqlPool = mysql.createPool(config);

    setInterval(
        function() {
            self.applyChanges();
        },
        500
    );
    setInterval(
        function() {
            self.save();
        },
        5000
    );
};
module.exports = MysqlChunkStore;
github drorm / meteor-sql / server / dbinit.js View on Github external
/*
 * Meteor SQL Driver main file. Initializes the driver and sets up all the tables.
 */
var require = __meteor_bootstrap__.require,
Future = require('fibers/future'),
//Using the node.js MYSQL driver from https://github.com/felixge/node-mysql
mysql = require('mysql');

start = new Date();
console.log('\n----------' + new Date() + ' SQL Driver Starting --------');


//Create the connection pool using the config info in dbconfig.js
var pool = mysql.createPool(Devwik.SQL.Config.dbConfig);

//Get the connection
pool.getConnection(function(err, connection) {
	var query;
	if (err) throw err;
	Devwik.SQL.connection = connection;//provide global access to the connection

	//Get the list of tables in the db
	query = connection.query('show tables', function(err, result) {
		if (err) throw err;
		Fiber(function() {

			//Get the list of views in the db
			Devwik.SQL.View.getViews();

			//Set up the table where we track changes to the db
github re-figure / refigure / back / db.js View on Github external
function createPool() {
    let dbConf = config.get('mysql');
    dbConf.multipleStatements = true;
    return mysql.createPool(dbConf);
}
github DuckDeck / blog / server / sqlhelp / mysql.js View on Github external
var db    = {};  
var mysql = require('mysql');  
const result = require('../model/result')
var pool  = mysql.createPool({  
  connectionLimit : 10,  
  host            : 'localhost',  
  user            : 'test',  
  password        : '123456',  
  database        : 'blog' ,
});

var poolCity  = mysql.createPool({  
    connectionLimit : 10,  
    host            : 'localhost',  
    user            : 'test',  
    password        : '123456',  
    database        : 'city' ,
  });
  //host            : 'bqbbq.com',  
//Issue Point there is a bug in the mysql pool system, it looks like it can cache some query when the sql is the some and the 
//request result will not change, this is not looks
//it's not a bug ,it's my issue
db.exec = function(sql,data,db_name='blog'){
    return new Promise(function(resolve,reject){
        if (!sql) {  
            reject(result.create(-100)) 
            return;  
        }
github smartscenes / sstk / server / lib / sql-querier.js View on Github external
function SQLQuerier(params) {
  if (params && params.host && params.user && params.password && params.database) {
    this.pool = mysql.createPool({
      connectionLimit : 100, //important
      host     : params.host,
      port     : params.port,
      user     : params.user,
      password : params.password,
      database : params.database,
      debug    : false
    });
  } else {
    throw new Error('Tried to create SQLQuerier with invalid params:' + params);
  }
}
github mozilla / fxa-oauth-server / lib / db / mysql / index.js View on Github external
function MysqlStore(options) {
  if (options.charset && options.charset !== 'UTF8_UNICODE_CI') {
    logger.warn('createDatabase', { charset: options.charset });
  } else {
    options.charset = 'UTF8_UNICODE_CI';
  }
  options.typeCast = function(field, next) {
    if (field.type === 'TINY' && field.length === 1) {
      return field.string() === '1';
    }
    return next();
  };
  logger.info('pool.create', { options: options });
  var pool = this._pool = mysql.createPool(options);
  pool.on('enqueue', function() {
    logger.info('pool.enqueue', {
      queueLength: pool._connectionQueue && pool._connectionQueue.length
    });
  });
}