resolveColumnType method

ResolvedType resolveColumnType(
  1. String? typeName, {
  2. bool isStrict = false,
})

Resolves a column type via its typename, see the linked rules below. Additionally, if driftExtensions are enabled, we support IsBoolean and IsDateTime hints if the type name contains BOOL or DATE, respectively. https://www.sqlite.org/datatype3.html#determination_of_column_affinity

Implementation

ResolvedType resolveColumnType(String? typeName, {bool isStrict = false}) {
  if (typeName == null) {
    return const ResolvedType(type: BasicType.blob);
  }

  // S if a custom resolver is installed and yields a type for this column:
  final custom = statementOptions?.resolveTypeFromText?.call(typeName);
  if (custom != null) {
    return custom;
  }

  final upper = typeName.toUpperCase();
  if (upper.contains('INT')) {
    if (driftExtensions && upper.contains('INT64')) {
      return const ResolvedType(type: BasicType.int, hints: [IsBigInt()]);
    } else {
      return const ResolvedType(type: BasicType.int);
    }
  }
  if (upper.contains('CHAR') ||
      upper.contains('CLOB') ||
      upper.contains('TEXT')) {
    return const ResolvedType(type: BasicType.text);
  }

  if (upper.contains('BLOB')) {
    return const ResolvedType(type: BasicType.blob);
  }

  if (isStrict && upper == 'ANY') {
    return const ResolvedType(type: BasicType.any);
  }

  if (driftExtensions) {
    if (upper.contains('BOOL')) {
      return const ResolvedType.bool();
    }
    if (upper.contains('DATE')) {
      return ResolvedType(
        type: driftUseTextForDateTime ? BasicType.text : BasicType.int,
        hints: const [IsDateTime()],
      );
    }

    if (upper.contains('ENUMNAME')) {
      return const ResolvedType(type: BasicType.text);
    }

    if (upper.contains('ENUM')) {
      return const ResolvedType(type: BasicType.int);
    }
  }

  return const ResolvedType(type: BasicType.real);
}