forNullableType<Dart> static method

DriftSqlType<Object> forNullableType<Dart>()

A variant of forType that also works for nullable Dart types.

Using forType should pretty much always be preferred over this method, this one just exists for backwards compatibility.

Implementation

static DriftSqlType forNullableType<Dart>() {
  // Lookup the type in the map first for faster lookups. Go back to a full
  // typecheck where that doesn't work (which can be the case for complex
  // type like `forNullableType<FutureOr<int?>>`).
  final type = _dartToDrift[Dart] ??
      values.whereType<BaseSqlType<Dart>>().singleOrNull;

  if (type == null) {
    throw ArgumentError('Could not find a matching SQL type for $Dart');
  }

  return type as DriftSqlType;
}