DBPostgreSQLAdapter.fromConfig constructor
DBPostgreSQLAdapter.fromConfig(})
Implementation
factory DBPostgreSQLAdapter.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 DBPostgreSQLAdapter(
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,
);
}