read<T extends Object> method
- BaseSqlType<
T> type, - Object? sqlValue
Maps a raw sqlValue
to Dart given its sql type
(typically a
DriftSqlType).
Implementation
T? read<T extends Object>(BaseSqlType<T> type, Object? sqlValue) {
if (sqlValue == null) return null;
return switch (type) {
DriftSqlType.bool => (sqlValue != 0 && sqlValue != false),
DriftSqlType.string => sqlValue.toString(),
DriftSqlType.bigInt => switch (sqlValue) {
BigInt() => sqlValue,
int() => BigInt.from(sqlValue),
_ => BigInt.parse(sqlValue.toString()),
},
DriftSqlType.int => switch (sqlValue) {
int() => sqlValue,
BigInt() => sqlValue.toInt(),
_ => int.parse(sqlValue.toString()),
},
DriftSqlType.dateTime => _readDateTime(sqlValue),
DriftSqlType.blob => switch (sqlValue) {
String() => Uint8List.fromList(sqlValue.codeUnits),
_ => sqlValue,
},
DriftSqlType.double => switch (sqlValue) {
BigInt() => sqlValue.toDouble(),
_ => (sqlValue as num).toDouble(),
},
DriftSqlType.any => DriftAny(sqlValue),
CustomSqlType() => type.read(sqlValue),
DialectAwareSqlType() => type.read(this, sqlValue),
} as T;
}