validate method

void validate(
  1. Map<String, dynamic> row
)

التحقق من أن الصف يطابق المخطط

Implementation

void validate(Map<String, dynamic> row) {
  for (final col in columns) {
    final value = row[col.name];
    if (value == null) {
      if (!col.isNullable && !col.isPrimaryKey) {
        throw Exception('Column "${col.name}" cannot be null');
      }
      continue;
    }
    switch (col.type) {
      case DataType.intType:
        if (value is! int) throw Exception('${col.name} must be int, got ${value.runtimeType}');
      case DataType.textType:
        if (value is! String) throw Exception('${col.name} must be text, got ${value.runtimeType}');
      case DataType.realType:
        if (value is! num) throw Exception('${col.name} must be real, got ${value.runtimeType}');
      case DataType.boolType:
        if (value is! bool) throw Exception('${col.name} must be bool, got ${value.runtimeType}');
    }
  }
}