How to use the machinepack-mysql.getConnection function in machinepack-mysql

To help you get started, we’ve selected a few machinepack-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 balderdashy / sails-mysql / helpers / private / connection / spawn-connection.js View on Github external
module.exports = function spawnConnection(datastore, cb) {
  // Validate datastore
  if (!datastore || !datastore.manager || !datastore.config) {
    return cb(new Error('Spawn Connection requires a valid datastore.'));
  }

  MySQL.getConnection({
    manager: datastore.manager,
    meta: datastore.config
  })
  .switch({
    error: function error(err) {
      return cb(err);
    },
    failed: function failedToConnect(err) {
      return cb(err);
    },
    success: function success(connection) {
      return cb(null, connection.connection);
    }
  });
};
github balderdashy / sails-mysql / test / support / bootstrap.js View on Github external
Support.Teardown = function teardown(tableName, cb) {
  var manager = adapter.datastores[_.first(_.keys(adapter.datastores))].manager;
  MySQL.getConnection({
    manager: manager,
    meta: Support.Config
  }).exec(function getConnectionCb(err, report) {
    if (err) {
      return cb(err);
    }

    var query = 'DROP TABLE IF EXISTS `' + tableName + '`;';
    MySQL.sendNativeQuery({
      connection: report.connection,
      nativeQuery: query
    }).exec(function dropTableCb(err) {
      if (err) {
        return cb(err);
      }
github balderdashy / sails-mysql / test / support / bootstrap.js View on Github external
Support.Seed = function seed(tableName, cb) {
  var manager = adapter.datastores[_.first(_.keys(adapter.datastores))].manager;
  MySQL.getConnection({
    manager: manager,
    meta: Support.Config
  }).exec(function getConnectionCb(err, report) {
    if (err) {
      return cb(err);
    }

    var query = [
      'INSERT INTO `' + tableName + '` (`fieldA`, `fieldB`, `fieldC`, `fieldD`) ',
      'values (\'foo\', \'bar\', null, null), (\'foo_2\', \'bAr_2\', $1, $2);'
    ].join('');

    MySQL.sendNativeQuery({
      connection: report.connection,
      nativeQuery: query,
      valuesToEscape: [new Buffer([1,2,3]), new Date('2001-06-15 12:00:00')]