load databse to app[config.delegate
@param {Object} config config for load
- delegate: load model to app[delegate]
- baeDir: where model located
- other sequelize configures(databasem username, password, etc...)
@return {Object} sequelize instance
198557
function loadDatabase(config = {}) {
    if (typeof config.ignore === 'string' || Array.isArray(config.ignore)) {
      app.deprecate(`[egg-sequelize] if you want to exclude ${config.ignore} when load models, please set to config.sequelize.exclude instead of config.sequelize.ignore`);
      config.exclude = config.ignore;
      delete config.ignore;
    }

    const sequelize = new app.Sequelize(config.database, config.username, config.password, config);

    const delegate = config.delegate.split('.');
    const len = delegate.length;

    let model = app;
    let context = app.context;
    for (let i = 0; i < len - 1; i++) {
      model = model[delegate[i]] = model[delegate[i]] || {};
      context = context[delegate[i]] = context[delegate[i]] || {};
    }

    if (model[delegate[len - 1]]) {
      throw new Error(`[egg-sequelize] app[${config.delegate}] is already defined`);
    }

    Object.defineProperty(model, delegate[len - 1], {
      value: sequelize,
      writable: false,
      configurable: true,
    });

    const DELEGATE = Symbol(`context#sequelize_${config.delegate}`);
    Object.defineProperty(context, delegate[len - 1], {
      get() {
        // context.model is different with app.model
        // so we can change the properties of ctx.model.xxx
        if (!this[DELEGATE]) this[DELEGATE] = Object.create(model[delegate[len - 1]]);
        return this[DELEGATE];
      },
      configurable: true,
    });

    const modelDir = path.join(app.baseDir, 'app', config.baseDir);

    const models = [];
    const target = Symbol(config.delegate);

    app.loader.loadToApp(modelDir, target, {
      caseStyle: 'upper',
      ignore: config.exclude,
      filter(model) {
        if (!model || !model.sequelize) return false;
        models.push(model);
        return true;
      },
      initializer(factory) {
        if (typeof factory === 'function') {
          return factory(app, sequelize);
        }
      },
    });
    Object.assign(model[delegate[len - 1]], app[target]);

    models.forEach(model => {
      typeof model.associate === 'function' && model.associate();
    });

    return model[delegate[len - 1]];
  }
391541
public static function loadConfig($config = null)
    {
        if ($config !== null) {
            Configure::write('CakeResque', $config);
        }

        if (
            ($hasCheck = method_exists('Configure', 'check')) && !Configure::check('CakeResque') ||
            !$hasCheck && !self::checkConfig('CakeResque')
        ) {
            Configure::load('CakeResque.config');
        }
    }
1055579
async function createApp(middlewareConfig) {
  const app = new Koa()

  const middleware = await setupMiddleware(middlewareConfig, app)

  if (app.env == 'production') {
    app.proxy = true
  }

  return {
    app,
    middleware,
  }
}
494601
function _initMigrations() {
  return new Umzug({
    storage: 'sequelize',
    storageOptions: {
      sequelize: this.sequelize,
    },
    migrations: {
      params: [this.sequelize.getQueryInterface(), Sequelize],
      path: path.join(__dirname, 'migrations'),
      pattern: /\.js$/,
    },
  });
}
443173
function (dbname, callback) {
    var executeDB = load('db');
    this.internals.argv._.push(dbname);
    this.internals.mode = 'create';
    return Promise.fromCallback(
      function (callback) {
        executeDB(this.internals, this.config, callback);
      }.bind(this)
    ).asCallback(callback);
  }
183812
function (config) {
        config = config || {};
        this.api_key = config.api_key;
        this.host = config.host || undefined;
        this.api_version = config.api_version || undefined;
        this.dev_mode = config.dev_mode || false;
        return this;
    }
535947
def options
      Dotenv.load

      seq_config = ENV.keys.select { |key| key =~ /^SEQUELIZER_/ }.inject({}) do |config, key|
        new_key = key.gsub(/^SEQUELIZER_/, '').downcase
        config[new_key] = ENV[key]
        config
      end

      db_config = ENV.keys.select { |key| key =~ /_DB_OPT_/ }.inject({}) do |config, key|
        new_key = key.downcase
        config[new_key] = ENV[key]
        config
      end

      db_config.merge(seq_config)
    end
1139300
function load(method, config) {
  return function(patterns, options) {
    var opts = mergeOptions(this, config, options);
    var loader = createLoader(opts, this[method]);
    return loader.apply(this, arguments);
  };
}
1098228
function loadConfig(configPath) {
	return new Promise((resolve, reject) => {
		configPath = resolveConfigPath(configPath);
		let config;
		try {
			config = loadLocalConfigUnmodified(configPath);
			if (!config) {
				config = loadLocalConfigWithJs(configPath);
			}
			if (!config) {
				config = loadLocalConfigWithJson(configPath);
			}
			if (program.config && !config) {
				return reject(new Error(`The config file "${configPath}" could not be loaded`));
			}
		} catch (error) {
			return reject(
				new Error(`There was a problem loading "${configPath}":\n${error.stack}`)
			);
		}

		// Allow loaded configs to return a promise
		Promise.resolve(config).then(config => {
			resolve(defaultConfig(config || {}));
		});
	});
}
428573
function loadTemplates(appName) {

    let appConfig = AmorphicContext.applicationConfig[appName] || {};
    let applicationSource = AmorphicContext.applicationSource;
    let applicationSourceMap = AmorphicContext.applicationSourceMap;
    let controllerPath = (appConfig.appConfig.controller || 'controller.js');
    let matches = controllerPath.match(/(.*?)([0-9A-Za-z_]*)\.js$/);
    let prop = matches[2];
    let baseTemplate = buildBaseTemplate(appConfig);

    applicationSource[appName] = '';
    applicationSourceMap[appName] = '';

    // Inject into it any db or persist attributes needed for application
    if (appConfig.initObjectTemplate && typeof appConfig.initObjectTemplate === 'function') {
        appConfig.initObjectTemplate(baseTemplate);
    }

    return [
        baseTemplate,
        getTemplates(baseTemplate, appConfig.appPath, [prop + '.js'], appConfig, appName)
    ];
}
1176935
function(config) {
    this._config = this._defaultConfig();
    if (!config) return true;
    
    var datastore;
    
    switch(config.adapter) {
    case 'disk':
      datastore = this._adapters.disk.connection();
      break;
      
    case 'redis':
      datastore = this._adapters.redis.connection(config.redis);
      break;
      
    case 'memory':
    default:
      return true; // Memory adapter by default
    }
    
    // Set connection
    this._config.connections.datastore = datastore;
    return true;
  }
1251443
function getEngine(name) {
            if (!dbconfig.has(name)) {
                d.fatal("Trying to access data storage that is not configured:", name);
            }
            var conf = dbconfig.get(name);
            if (!conf.engine) {
                conf.engine = engine(conf.url);
            }
            return conf.engine;
        }
991257
function () {
    var appConfigPath = this.root.join('config', 'application'),
        envConfigPath = this.root.join('config', 'environment', this.env + '.js'),
        config, appConfig, envConfig;

    debug('configuring');

    // require the config object, given as the argument to exported `configure`
    // functions in application/environment config files
    config = require(this._root.join('lib', 'config'))(this);

    // only load application config if we're in an app
    if (this.inApp) {
      // application.js configuration
      appConfig = require(appConfigPath)(config);

      // environmental override configs are optional
      if (fs.existsSync(envConfigPath)) {
        // environment config overrides eg development.js
        // should export a function that takes the config object as an arg
        envConfig = require(envConfigPath)(config);
      }
    }

    this.config = config;

    return config;
  }
566591
function(config, options) {
      // Make sure config is initialised
      if( ! config ) {
        config = JSON.parse(JSON.stringify(self.defaults));
      }


      var datasetConfig = JSON.parse(JSON.stringify(config));
      var optionsIn = JSON.parse(JSON.stringify(options));
      for (var k in optionsIn) {
        datasetConfig[k] = optionsIn[k];
      }

      return datasetConfig;
    }
1252055
function configureMiddlewares(app, config) {
    config = config || {};

    // setup request helpers
    utils.extendHttpRequest();

    // setup response helpers
    utils.extendHttpResponse();

    //
    // order is meaningful for some express middlewares
    //

    // NOTE: this should be the first middleware
    if (config.logger) {
        app.use(require('./logger')(config.logger));
    }

    // NOTE: this should be placed "high" within middleware stack
    if (config.compress || config.compression) {
        app.use(require('compression')(config.compress || config.compression));
    }

    // NOTE: this should be before "session" middleware using "cookie store"
    if (config.cookieParser) {
        app.use(require('cookie-parser')(config.cookieParser));
    }

    // "_method" body param or "x-http-method-override' header
    if (config.methodOverride) {
        app.use(require('method-override')(config.methodOverride));
    }

    // "cors" request
    if (config.cors) {
        app.use(require('./cors')(config.cors));
    }

    // NOTE: this should be before "passport" middlewares
    if (config.session) {
        app.use(require('./session')(config.session));
    }

    // this should be after "session" middleware
    if (config.csrf || config.csurf) {
        app.use(require('csurf')(config.csrf || config.csurf));
    }

    // multipart/form-data
    if (config.multipart) {
        app.use(require('./multipart')(config.multipart));
    }

    // application/json
    if (config.json) {
        app.use(require('body-parser').json(config.json));
    }

    // application/x-www-form-urlencoded
    if (config.urlencoded) {
        config.urlencoded.extended = !!config.urlencoded.extended;
        app.use(require('body-parser').urlencoded(config.urlencoded));
    }

    // plain/text
    if (config.text) {
        app.use(require('body-parser').text(config.text));
    }

    // application/octet-stream
    if (config.raw) {
        app.use(require('body-parser').raw(config.text));
    }

    return app;
}
377821
function loadConfigs() {
    this.appConfigs = [];
    this.gatewayNb = 0;
    this.monolithicNb = 0;
    this.microserviceNb = 0;
    this.uaaNb = 0;

    // Loading configs
    this.debug(`Apps folders: ${this.appsFolders}`);
    this.appsFolders.forEach(appFolder => {
        const path = this.destinationPath(`${this.directoryPath + appFolder}/.yo-rc.json`);
        const fileData = this.fs.readJSON(path);
        if (fileData) {
            const config = fileData['generator-jhipster'];

            if (config.applicationType === 'monolith') {
                this.monolithicNb++;
            } else if (config.applicationType === 'gateway') {
                this.gatewayNb++;
            } else if (config.applicationType === 'microservice') {
                this.microserviceNb++;
            } else if (config.applicationType === 'uaa') {
                this.uaaNb++;
            }

            this.portsToBind = this.monolithicNb + this.gatewayNb;
            config.appFolder = appFolder;
            this.appConfigs.push(config);
        } else {
            this.error(`Application '${appFolder}' is not found in the path '${this.directoryPath}'`);
        }
    });
}
119303
function createAction(config){
    // make a copy of config with defaults
    config = basis.object.extend({
      prepare: nothingToDo,
      request: nothingToDo
    }, config);

    // if body is function take in account special action context
    if (typeof config.body == 'function')
    {
      var bodyFn = config.body;
      config.body = function(){
        return bodyFn.apply(this.context, this.args);
      };
    }

    // splice properties
    var fn = basis.object.splice(config, ['prepare', 'request']);
    var callback = basis.object.merge(
      DEFAULT_CALLBACK,
      basis.object.splice(config, ['start', 'success', 'failure', 'abort', 'complete'])
    );

    // lazy transport
    var getTransport = basis.fn.lazyInit(function(){
      var transport = resolveTransport(config);

      transport.addHandler(CALLBACK_HANDLER, callback);

      return transport;
    });

    return function action(){
      // this - instance of AbstractData
      if (this.state != STATE_PROCESSING)
      {
        if (fn.prepare.apply(this, arguments))
        {
          /** @cut */ basis.dev.info('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
          return Promise.reject('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
        }

        var request;
        var requestData = basis.object.complete({
          origin: this,
          bodyContext: {
            context: this,
            args: basis.array(arguments)
          }
        }, fn.request.apply(this, arguments));

        // if body is function take in account special action context
        if (typeof requestData.body == 'function')
        {
          var bodyFn = requestData.body;
          requestData.body = function(){
            return bodyFn.apply(this.context, this.args);
          };
        }

        // do a request
        if (request = getTransport().request(requestData))
          return new Promise(function(fulfill, reject){
            request.addHandler(PROMISE_REQUEST_HANDLER, {
              request: request,
              fulfill: fulfill,
              reject: reject
            });
          });

        return Promise.reject('Request is not performed');
      }
      else
      {
        /** @cut */ basis.dev.warn('Context in processing state. Operation aborted. Context: ', this);
        return Promise.reject('Context in processing state, request is not performed');
      }
    };
  }