create static method

Future<DartApiDB> create(
  1. DbConfig config
)

Creates and returns an instance of DartApiDB based on the provided config.

Automatically selects the appropriate database driver based on DbType. After instantiation, the database connection is established by calling connect().

Throws UnsupportedError if the provided DbType is not supported.

Implementation

static Future<DartApiDB> create(DbConfig config) async {
  late final DartApiDB db;

  switch (config.type) {
    case DbType.postgres:
      db = PostgresDatabase(config);
      break;
    case DbType.mysql:
      db = MySqlDatabase(config);
      break;
  }

  await db.connect();
  return db;
}