readTable method

Future<MssqlTableSchema?> readTable(
  1. String identifier
)

One table by name, such as dbo.Orders or Orders (which means dbo).

Returns null when nothing of that name exists, so that "no such table" is a value the caller handles rather than an exception it must catch.

Implementation

Future<MssqlTableSchema?> readTable(String identifier) async {
  final parts = MssqlMultipartIdentifier.parse(
    identifier,
    maximumParts: 2,
  ).parts;
  final schema = parts.length == 2 ? parts.first : 'dbo';
  final name = parts.last;
  final tables = await readTables(
    schemas: <String>{schema},
    include: <String>[name],
  );
  for (final table in tables) {
    if (table.name.toLowerCase() == name.toLowerCase()) return table;
  }
  return null;
}