reviveColumn function

Column reviveColumn(
  1. ConstantReader cr
)

Implementation

Column reviveColumn(ConstantReader cr) {
  ColumnType columnType;

  var indexTypeObj = cr.peek('indexType')?.objectValue;
  indexTypeObj ??= cr.revive().namedArguments['indexType'];

  var columnObj = cr
      .peek('type')
      ?.objectValue
      .getField('name')
      ?.toStringValue();
  var indexType =
      IndexType.values[indexTypeObj?.getField('index')?.toIntValue() ??
          IndexType.none.index];

  if (const TypeChecker.typeNamed(
    PrimaryKey,
  ).isAssignableFromType(cr.objectValue.type!)) {
    indexType = IndexType.primaryKey;
  }

  if (columnObj != null) {
    columnType = _ColumnType(columnObj);
  } else {
    // Default to varchar
    columnType = ColumnType.varChar;
  }

  return Column(
    isNullable: cr.peek('isNullable')?.boolValue ?? false,
    length: cr.peek('length')?.intValue ?? 255,
    defaultValue: cr.peek('defaultValue')?.objectValue,
    type: columnType,
    indexType: indexType,
  );
}