How to use the mysql2/promise.createPool function in mysql2

To help you get started, we’ve selected a few mysql2 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 lupyuen / AWSIOT / nodejs / IndexAWSLogs.js View on Github external
const main = (event, context, callback) => {
  //  This is the main execution scope.  All non-system require(...)
  //  statements must be put here.

  //  This missing module is normally not allowed for inline lambda.  But
  //  autorequire will install the module automatically for us.
  const mysql = require('mysql2/promise');

  //  Create pool of database connections.
  const pool = mysql.createPool({
    host: 'iotdb.culga9y9tfvw.us-west-2.rds.amazonaws.com',
    user: 'root',
    password: 'iotattp4me',
    database: 'iotdb',
  });

  function handler(input, context2, callback2) {
    //  This is the main program flow after resolving the missing modules.
    if (input.domain) delete input.domain;  //  TODO: Contains self-reference loop.
    console.log('Input:', JSON.stringify(input, null, 2));
    console.log('Context:', context2);
    //  Don't index response to set desired state.
    if (input.state && input.state.desired) {
      return callback2(null, 'Ignoring response to set desired state');
    }
    let device = null;
github sidorares / node-mysql2 / examples / promise-co-await / await.js View on Github external
console.log('after second sleep');
  let start = +new Date();
  console.log(
    await Promise.all([
      c.execute('select sleep(2.5)'),
      c.execute('select sleep(2.5)')
    ])
  );
  console.log(
    'after 2+3 parallel sleep which is in fact not parallel because commands are queued per connection'
  );
  let end = +new Date();
  console.log(end - start);
  await c.end();

  const p = mysql.createPool({
    port: 3306,
    user: 'testuser',
    namedPlaceholders: true,
    password: 'testpassword'
  });
  console.log(await p.execute('select sleep(0.5)'));
  console.log('after first pool sleep');
  start = +new Date();
  console.log(
    await Promise.all([
      p.execute('select sleep(2.5)'),
      p.execute('select sleep(2.5)')
    ])
  );
  console.log('after 2+3 parallel pool sleep');
  end = +new Date();
github SideProjectGuys / invite-manager-bot / src / framework / services / DatabaseService.ts View on Github external
public constructor(client: IMClient) {
		this.client = client;
		for (const db of client.config.databases) {
			const range = db.range;
			delete db.range;

			const pool = mysql.createPool(db);
			for (let i = range.from; i <= range.to; i++) {
				this.pools.set(i, pool);
			}

			this.dbCount = Math.max(this.dbCount, range.to);
		}

		console.log(`We're connected to ${this.dbCount} db shards on ${client.config.databases.length} different servers`);

		setInterval(() => this.syncDB(), 10000);
	}
github kkrisz1 / staruml-reverse-db / mysql / MySqlDbClient.js View on Github external
_cmdExecStmnt(requestId, sqlStr, inputParams) {
    if (!this.pool) {
      this.pool = mysql.createPool(Object.assign(this.options, this.poolConfig));
    }

    return this.pool.query(sqlStr.toString(), inputParams).then(([rows, fields]) => {
      return {rowCount: rows.length, rows: rows};
    });
  }
github planarnetwork / raptor / src / transfer-pattern-worker.ts View on Github external
function getDatabase() {
  return require("mysql2/promise").createPool({
    host: process.env.DATABASE_HOSTNAME || "localhost",
    user: process.env.DATABASE_USERNAME || "root",
    password: process.env.DATABASE_PASSWORD || "",
    database: process.env.OJP_DATABASE_NAME || "raptor",
    connectionLimit: 5,
  });
}
github Yengas / nodejs-docker-bootstrap / application / src / database.js View on Github external
return module.exports = (databaseConfig) => mysql.createPool(databaseConfig);
github midas-science / midas / source / Loader / MySQLLoader.js View on Github external
constructor(config) {
    	super(config);
    	this.db_config = {
    		connectionLimit: 10,
			host:this.config._target.host,
			port:this.config._target.port,
			user:this.config._target.user,
			password:this.config._target.password,
			database:this.config._target.database
		};
		this.pool = mysql.createPool(this.db_config);    	
    }
github mozilla / voice-web / server / src / lib / model / db / mysql.ts View on Github external
async createPool(): Promise {
    return mysql2.createPool(this.getMysqlOptions());
  }
github Liquid-Zhangliquan / ycyfans-map / server / db / mysqlConf.js View on Github external
const mysql = require('mysql2/promise');

const pool = mysql.createPool({
  host: '',
  user: '',
  password: '',
  database: '',
});

module.exports = pool;
github upframe / api / services / database.ts View on Github external
constructor() {
    try {
      const pool: mysql.Pool = mysql.createPool({
        host: process.env.DB_HOST,
        user: process.env.DB_USER,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_NAME,
      })
      if (pool) logger.verbose('Database OK')

      this.pool = pool
    } catch (err) {
      logger.error('Database NOT OK')
    }
  }