How to use loopback-connector - 10 common examples

To help you get started, we’ve selected a few loopback-connector 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 hyperledger-archives / fabric-sdk-rest / packages / loopback-connector-fabric / lib / fabricconnector.js View on Github external
constructor(settings){
    super();
    //console.log(">> HFCSDKConnector");
    Connector.call(this, 'hfc-sdk', settings);

    this.settings = settings; // Store the settings for ease of access

    Common.validateSettings(this.settings);

    //logger.info("Info output test");
    //logger.debug("Debugging output test");
    //logger.error("Error output test");
  };
github strongloop / loopback-datasource-juggler / lib / transaction.js View on Github external
}, options.timeout);
      }
      cb(err, transaction);
    });
  } else {
    process.nextTick(function() {
      const err = new Error(g.f('{{Transaction}} is not supported'));
      cb(err);
    });
  }
  return cb.promise;
};

// Promisify the transaction apis
if (Transaction) {
  jutil.mixin(Transaction.prototype, ObserverMixin);
  /**
   * Commit a transaction and release it back to the pool.
   *
   * Example:
   *
   * ```js
   * MyModel.beginTransaction('READ COMMITTED', function(err, tx) {
   *   // some crud operation of your choice
   *   tx.commit(function(err) {
   *     // release the connection pool upon committing
   *     tx.close(err);
   *   });
   * });
   * ```
   *
   * @callback {Function} cb Callback function.
github strongloop / loopback-datasource-juggler / lib / transaction.js View on Github external
* Example:
   *
   * ```js
   * MyModel.beginTransaction('READ COMMITTED', function(err, tx) {
   *   // some crud operation of your choice
   *   tx.commit(function(err) {
   *     // release the connection pool upon committing
   *     tx.close(err);
   *   });
   * });
   * ```
   *
   * @callback {Function} cb Callback function.
   * @returns {Promise|undefined} Returns a callback promise.
   */
  Transaction.prototype.commit = function(cb) {
    cb = cb || utils.createPromiseCallback();
    if (this.ensureActive(cb)) {
      const context = {
        transaction: this,
        operation: 'commit',
      };
      this.notifyObserversAround('commit', context,
        done => {
          this.connector.commit(this.connection, done);
        },
        err => {
          // Deference the connection to mark the transaction is not active
          // The connection should have been released back the pool
          this.connection = null;
          cb(err);
        });
github strongloop / loopback-datasource-juggler / lib / datasource.js View on Github external
// No need to do anything here.
      cb();
    };
    return handleExecute();
  } else if (connector.beginTransaction) {
    // Create a database source transaction.
    transaction.exec =
    transaction.commit = function(cb) {
      ensureTransaction(this.currentTransaction, cb).commit(cb);
    };
    transaction.rollback = function(cb) {
      ensureTransaction(this.currentTransaction, cb).rollback(cb);
    };
    // Always use callback / promise due to the use of beginTransaction()
    cb = cb || utils.createPromiseCallback();
    Transaction.begin(connector, options, transactionCreated);
    return cb.promise;
  } else {
    throw new Error(g.f('DataSource does not support transactions'));
  }
};
github strongloop / loopback-connector-couchdb2 / lib / couchdb.js View on Github external
function CouchDB(name, settings, ds) {
  // Injection for tests
  this.CouchDBDriver = settings.Driver || Driver;
  debug('CouchDB constructor settings: %j', settings);
  Connector.call(this, name, settings);
  this.debug = settings.debug || debug.enabled;
  this.dataSource = ds;

  if (!settings.url && (!settings.username || !settings.password)) {
    throw new Error(g.f('Invalid settings: "url" OR "username"' +
      ' AND "password" required'));
  }
  this.options = _.merge({}, settings);
  // If settings.url is not set, then setup account/password props.
  if (!this.options.url) {
    this.options.account = settings.username;
    this.options.password = settings.password;
  }
  this.pool = {};
};
github strongloop / loopback-datasource-juggler / lib / transaction.js View on Github external
});
    }
    return cb.promise;
  };

  Transaction.prototype.ensureActive = function(cb) {
    // Report an error if the transaction is not active
    if (!this.connection) {
      process.nextTick(() => {
        cb(new Error(g.f('The {{transaction}} is not active: %s', this.id)));
      });
    }
    return !!this.connection;
  };

  Transaction.prototype.toJSON = function() {
    return this.id;
  };

  Transaction.prototype.toString = function() {
    return this.id;
  };
}

TransactionMixin.Transaction = Transaction;
github strongloop / loopback-datasource-juggler / lib / transaction.js View on Github external
Transaction.prototype.ensureActive = function(cb) {
    // Report an error if the transaction is not active
    if (!this.connection) {
      process.nextTick(() => {
        cb(new Error(g.f('The {{transaction}} is not active: %s', this.id)));
      });
    }
    return !!this.connection;
  };

  Transaction.prototype.toJSON = function() {
    return this.id;
  };

  Transaction.prototype.toString = function() {
    return this.id;
  };
}

TransactionMixin.Transaction = Transaction;
github strongloop / loopback-datasource-juggler / lib / transaction.js View on Github external
*  Example:
   *
   * ```js
   * MyModel.beginTransaction('READ COMMITTED', function(err, tx) {
   *   // some crud operation of your choice
   *   tx.rollback(function(err) {
   *     // release the connection pool upon committing
   *     tx.close(err);
   *   });
   * });
   * ```
   *
   * @callback {Function} cb Callback function.
   * @returns {Promise|undefined} Returns a callback promise.
   */
  Transaction.prototype.rollback = function(cb) {
    cb = cb || utils.createPromiseCallback();
    if (this.ensureActive(cb)) {
      const context = {
        transaction: this,
        operation: 'rollback',
      };
      this.notifyObserversAround('rollback', context,
        done => {
          this.connector.rollback(this.connection, done);
        },
        err => {
          // Deference the connection to mark the transaction is not active
          // The connection should have been released back the pool
          this.connection = null;
          cb(err);
        });
github strongloop / loopback-datasource-juggler / lib / transaction.js View on Github external
};
      this.notifyObserversAround('rollback', context,
        done => {
          this.connector.rollback(this.connection, done);
        },
        err => {
          // Deference the connection to mark the transaction is not active
          // The connection should have been released back the pool
          this.connection = null;
          cb(err);
        });
    }
    return cb.promise;
  };

  Transaction.prototype.ensureActive = function(cb) {
    // Report an error if the transaction is not active
    if (!this.connection) {
      process.nextTick(() => {
        cb(new Error(g.f('The {{transaction}} is not active: %s', this.id)));
      });
    }
    return !!this.connection;
  };

  Transaction.prototype.toJSON = function() {
    return this.id;
  };

  Transaction.prototype.toString = function() {
    return this.id;
  };
github strongloop / loopback-connector-mysql / lib / mysql.js View on Github external
// Copyright IBM Corp. 2012,2017. All Rights Reserved.
// Node module: loopback-connector-mysql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';
var g = require('strong-globalize')();

/*!
 * Module dependencies
 */
var mysql = require('mysql');

var SqlConnector = require('loopback-connector').SqlConnector;
var ParameterizedSQL = SqlConnector.ParameterizedSQL;
var EnumFactory = require('./enumFactory').EnumFactory;

var debug = require('debug')('loopback:connector:mysql');
var setHttpCode = require('./set-http-code');

/**
 * @module loopback-connector-mysql
 *
 * Initialize the MySQL connector against the given data source
 *
 * @param {DataSource} dataSource The loopback-datasource-juggler dataSource
 * @param {Function} [callback] The callback function
 */
exports.initialize = function initializeDataSource(dataSource, callback) {
  dataSource.driver = mysql; // Provide access to the native driver
  dataSource.connector = new MySQL(dataSource.settings);