DBMySQLAdapter.fromConfig constructor

DBMySQLAdapter.fromConfig(
  1. Map<String, dynamic>? config, {
  2. String? defaultDatabase,
  3. String? defaultUsername,
  4. String? defaultHost,
  5. int? defaultPort,
  6. int? minConnections,
  7. int? maxConnections,
  8. EntityRepositoryProvider? parentRepositoryProvider,
  9. String? workingPath,
})

Implementation

factory DBMySQLAdapter.fromConfig(Map<String, dynamic>? config,
    {String? defaultDatabase,
    String? defaultUsername,
    String? defaultHost,
    int? defaultPort,
    int? minConnections,
    int? maxConnections,
    EntityRepositoryProvider? parentRepositoryProvider,
    String? workingPath}) {
  boot();

  String? host = config?['host'] ?? defaultHost;
  int? port = config?['port'] ?? defaultPort;
  String? database = config?['database'] ?? config?['db'] ?? defaultDatabase;
  String? username =
      config?['username'] ?? config?['user'] ?? defaultUsername;
  String? password = (config?['password'] ?? config?['pass'])?.toString();

  int? confMinConnections = config?['minConnections'];
  if (confMinConnections != null) {
    minConnections = confMinConnections;
  }

  int? confMaxConnections = config?['maxConnections'];
  if (confMaxConnections != null) {
    maxConnections = confMaxConnections;
  }

  minConnections ??= 1;
  maxConnections ??= 3;

  var retCheckTablesAndGenerateTables =
      DBSQLAdapter.parseConfigDBGenerateTablesAndCheckTables(config);

  var generateTables = retCheckTablesAndGenerateTables[0];
  var checkTables = retCheckTablesAndGenerateTables[1];

  var populate = config?['populate'];
  Object? populateTables;
  Object? populateSource;
  Object? populateSourceVariables;

  if (populate is Map) {
    populateTables = populate['tables'];
    populateSource = populate['source'];
    populateSourceVariables = populate['variables'];
  }

  if (database == null) throw ArgumentError.notNull('database');
  if (username == null) throw ArgumentError.notNull('username');

  var logSql = DBSQLAdapter.parseConfigLogSQL(config) ?? false;

  return DBMySQLAdapter(
    database,
    username,
    password: password,
    host: host,
    port: port,
    minConnections: minConnections,
    maxConnections: maxConnections,
    generateTables: generateTables,
    checkTables: checkTables,
    populateTables: populateTables,
    populateSource: populateSource,
    populateSourceVariables: populateSourceVariables,
    parentRepositoryProvider: parentRepositoryProvider,
    workingPath: workingPath,
    logSQL: logSql,
  );
}