SupabaseIndexInfo.fromRow constructor

SupabaseIndexInfo.fromRow(
  1. List row,
  2. String nameConverter(
    1. String
    )
)

Creates a SupabaseIndexInfo instance from a raw SQL query result row.

The row is expected to be a list where:

  • row[0] is the original index name (String).
  • row[1] is a boolean indicating if the index is unique.
  • row[2] is a text representation of an array of original column names (e.g., {"col1","col2"}).

The nameConverter function is used to transform database identifiers (like index and column names) into Dart-conventional names (e.g., camelCase).

Implementation

factory SupabaseIndexInfo.fromRow(
  List<dynamic> row,
  String Function(String) nameConverter,
) {
  final originalIndexName = row[0] as String;
  final convertedName = nameConverter(originalIndexName);
  final isUnique = row[1] as bool? ?? false;
  // Index 2 is now the text representation of the array (e.g., {"col1","col2"})
  final columnsText = row[2] as String?;
  final originalColumnNames = _parsePgTextArray(
    columnsText,
  ); // Parse the string

  return SupabaseIndexInfo(
    name: convertedName, // Convert index name
    originalName: originalIndexName,
    localName: _makeSafeDartIdentifier(convertedName),
    isUnique: isUnique,
    columns:
        originalColumnNames
            .map(nameConverter)
            .toList(), // Convert column names
    originalColumns: originalColumnNames,
  );
}