Column.fromJson constructor
Column.fromJson(})
Implementation
factory Column.fromJson(String colName, Map<String, dynamic> json,
List<String> parentTableRequiredFields, Map<String, List<String>> enums,
{bool jsonbToDynamic = false,
Schemas schemas = Schemas.defaults,
String? schema,
String? tableName,
Map<String, JsonbModelConfig>? jsonbModels}) {
// PostgREST lists enum values on single-value columns only; array
// columns rely on [enums], keyed by `schema.type`.
final typeName = schemas.userTypeName(json['format']);
final enumValues = typeName == null
? <String>[]
: json['enum'] != null
? List<String>.from(json['enum'])
: enums[typeName] ?? <String>[];
// Look up JSONB model config if available
JsonbModelConfig? jsonbConfig;
if (jsonbModels != null && schema != null && tableName != null) {
final lookupKey = '$schema.$tableName.$colName';
jsonbConfig = jsonbModels[lookupKey];
}
return Column(
postgresFormat: json['format'],
dbColName: colName,
camelColName: snakeCasingToCamelCasing(colName),
enumValues: enumValues,
userType: typeName,
userTypeDartName:
typeName == null ? null : enumDartName(schemas.localNameOf(typeName)),
hasDefaultValue: json['description']?.contains('[supadart:serial]') ??
json['default'] != null,
description: json['description'],
maxLength: json['maxLength'],
isPrimaryKey: json['description']?.contains('<pk/>') ?? false,
isSerialType: json['description']?.contains('[supadart:serial]') ?? false,
isInRequiredColumn: parentTableRequiredFields.contains(colName),
jsonbToDynamic: jsonbToDynamic,
jsonbModelConfig: jsonbConfig,
);
}