getTableSchemeImpl method
Future<TableScheme?>
getTableSchemeImpl(
- String table,
- TableRelationshipReference? relationship, {
- Object? contextID,
override
Implementation that returns a TableScheme for table
.
contextID
should be Expando compatible. It informs that other calls to getTableSchemeImpl are in the same context and could have shared internal caches for the samecontextID
instance.
Implementation
@override
Future<TableScheme?> getTableSchemeImpl(
String table, TableRelationshipReference? relationship,
{Object? contextID}) async {
var connection = await catchFromPool();
try {
//_log.info('getTableSchemeImpl> $table ; relationship: $relationship');
var sql =
"SELECT column_name, data_type, column_default, is_updatable FROM information_schema.columns WHERE table_name = '$table'";
var results = await connection.mappedResultsQuery(sql);
var scheme = results.map((e) => e['']!).toList(growable: false);
if (scheme.isEmpty) {
await releaseIntoPool(connection);
return null;
}
var idFieldName = await _findIDField(connection, table, scheme);
var fieldsTypes = Map<String, Type>.fromEntries(scheme.map((e) {
var k = e['column_name'] as String;
var v = _toFieldType(e['data_type'] as String);
return MapEntry(k, v);
}));
notifyTableFieldTypes(table, fieldsTypes);
var fieldsReferencedTables = await _findFieldsReferencedTables(
connection, table,
contextID: contextID);
var relationshipTables = await _findRelationshipTables(
connection, table, idFieldName,
contextID: contextID);
var constraints = await _findConstraints(connection, table, fieldsTypes);
await releaseIntoPool(connection);
var tableScheme = TableScheme(table,
relationship: relationship != null,
idFieldName: idFieldName,
fieldsTypes: fieldsTypes,
constraints: constraints,
fieldsReferencedTables: fieldsReferencedTables,
relationshipTables: relationshipTables);
_log.info('$tableScheme');
return tableScheme;
} catch (_) {
await disposePoolElement(connection);
rethrow;
}
}