lib/jitsu/commands/databases.js
function createDatabase(database, callback) {

    database.type = databases.alias(database.type);

    //
    // Make sure that the user is passing in a valid database type
    //
    if (databases.available.indexOf(database.type) === -1) {
      jitsu.log.warn('Invalid database type ' + database.type.red);
      database.type = null;
      return promptForDatabase(callback);
    }

    jitsu.databases.create(database.type, database.name, function (err, a, res) {
      if (err || res.statusCode >= 400) {
        //
        // TODO: Refactor this error handling
        //
        if (err && (err.statusCode === 409 || err.statusCode === 404)) {
          jitsu.log.error('Database with name ' + database.name.magenta + ' already exists');
          jitsu.log.info('Try again with a new database name');
          database.name = null;
          return promptForDatabase(callback);
        }
        else {
          jitsu.log.error('Database could not be created');
          jitsu.log.error(err || ('Unknown error code: ' + res.statusCode));
          jitsu.log.error('Try again and if it still fails, please contact nodejitsu');
          return callback(err);
        }
      }
      else {
        jitsu.log.info('A new ' + database.type.magenta + ' has been created');
      }

      databases.get(database.name, callback);
    });
  }
function createDatabase(database, callback) {

    database.type = databases.alias(database.type);

    //
    // Make sure that the user is passing in a valid database type
    //
    if (databases.available.indexOf(database.type) === -1) {
      jitsu.log.warn('Invalid database type ' + database.type.red);
      database.type = null;
      return promptForDatabase(callback);
    }

    jitsu.databases.create(database.type, database.name, function (err, a, res) {
      if (err || res.statusCode >= 400) {
        //
        // TODO: Refactor this error handling
        //
        if (err && (err.statusCode === 409 || err.statusCode === 404)) {
          jitsu.log.error('Database with name ' + database.name.magenta + ' already exists');
          jitsu.log.info('Try again with a new database name');
          database.name = null;
          return promptForDatabase(callback);
        }
        else {
          jitsu.log.error('Database could not be created');
          jitsu.log.error(err || ('Unknown error code: ' + res.statusCode));
          jitsu.log.error('Try again and if it still fails, please contact nodejitsu');
          return callback(err);
        }
      }
      else {
        jitsu.log.info('A new ' + database.type.magenta + ' has been created');
      }

      databases.get(database.name, callback);
    });
  }
function createDatabase ( database , callback ) { database . type = databases . alias ( database . type ) ; // // Make sure that the user is passing in a valid database type // if ( databases . available . indexOf ( database . type ) === - 1 ) { jitsu . log . warn ( 'Invalid database type ' + database . type . red ) ; database . type = null ; return promptForDatabase ( callback ) ; } jitsu . databases . create ( database . type , database . name , function ( err , a , res ) { if ( err || res . statusCode >= 400 ) { // // TODO: Refactor this error handling // if ( err && ( err . statusCode === 409 || err . statusCode === 404 ) ) { jitsu . log . error ( 'Database with name ' + database . name . magenta + ' already exists' ) ; jitsu . log . info ( 'Try again with a new database name' ) ; database . name = null ; return promptForDatabase ( callback ) ; } else { jitsu . log . error ( 'Database could not be created' ) ; jitsu . log . error ( err || ( 'Unknown error code: ' + res . statusCode ) ) ; jitsu . log . error ( 'Try again and if it still fails, please contact nodejitsu' ) ; return callback ( err ) ; } } else { jitsu . log . info ( 'A new ' + database . type . magenta + ' has been created' ) ; } databases . get ( database . name , callback ) ; } ) ; }
Helper function to execute the database creation.
Helper function to execute the database creation .