How to use the loopback-connector.Transaction.begin function in loopback-connector

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 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-datasource-juggler / lib / transaction.js View on Github external
TransactionMixin.beginTransaction = function(options, cb) {
  cb = cb || utils.createPromiseCallback();
  if (Transaction) {
    const connector = this.getConnector();
    Transaction.begin(connector, options, function(err, transaction) {
      if (err) return cb(err);
      // NOTE(lehni) As part of the process of moving the handling of
      // transaction id and timeout from TransactionMixin.beginTransaction() to
      // Transaction.begin() in loopback-connector, switch to only setting id
      // and timeout if it wasn't taken care of already by Transaction.begin().
      // Eventually, we can remove the following two if-blocks altogether.
      if (!transaction.id) {
        // Set an informational transaction id
        transaction.id = uuid.v1();
      }
      if (options.timeout && !transaction.timeout) {
        transaction.timeout = setTimeout(function() {
          const context = {
            transaction: transaction,
            operation: 'timeout',
          };
github strongloop / loopback-datasource-juggler / lib / datasource.js View on Github external
DataSource.prototype.beginTransaction = function(options) {
  return Transaction.begin(this.connector, options);
};