importSchema function

Future<ImportedSchema> importSchema(
  1. SqlDatabase<Backend> db, {
  2. List<String>? tables,
})

Reads the selected database's physical catalog in one consistent catalog snapshot. No user rows are read, inferred, or changed. Omit tables to discover user tables; pass exact physical names to restrict the import. Unsupported columns exclude their whole table and produce blocking issues.

Implementation

Future<ImportedSchema> importSchema(
  SqlDatabase<Backend> db, {
  List<String>? tables,
}) {
  final requested = tables == null ? null : List<String>.unmodifiable(tables);
  if (requested != null &&
      (requested.isEmpty || requested.toSet().length != requested.length)) {
    throw ArgumentError.value(tables, 'tables', 'Choose distinct table names.');
  }
  if (db.inTransaction) {
    throw const OrmException(
      'IMPORT.SESSION',
      'Import needs its own catalog snapshot.',
    );
  }
  return db.transaction(
    (tx) => _importCatalog(tx, requested),
    options: switch (db.dialect) {
      SqlDialect.sqlite => const SqliteTransaction(),
      SqlDialect.postgres => const PostgresTransaction(
        isolation: .repeatableRead,
        readOnly: true,
      ),
      SqlDialect.mysql => const MysqlTransaction(
        isolation: .repeatableRead,
        readOnly: true,
      ),
      SqlDialect.mariadb => const MariadbTransaction(
        isolation: .repeatableRead,
        readOnly: true,
      ),
    },
  );
}