printDesign static method
void
printDesign()
Prints the design and structure of all registered collections.
This static method provides a comprehensive overview of all collection instances, including their fields, counts, events, and indexes. The output is displayed as JSON format using Console.json.
This is useful for debugging and understanding the database schema during development.
Implementation
static void printDesign() async {
CappConsole.clear();
var json = <String, Object?>{};
for (var collection in _allCollectionFree) {
var jsonCollection = <String, Object?>{};
var fieldsJson = <String, Object?>{};
for (var field in collection.form.fields.entries) {
var fieldModel = field.value;
fieldsJson.addAll({
field.key: {
'type': fieldModel.type,
'default': fieldModel.defaultValue?.call(),
'readonly': fieldModel.readonly,
'searchable': fieldModel.searchable,
'filterable': fieldModel.filterable,
'validators': fieldModel.validators.length,
'isHiddenJson': fieldModel.hideJson,
},
});
}
jsonCollection.addAll({
'name': collection.name,
'db': collection.db.databaseName,
'count': await collection.collection.count(),
'fields': fieldsJson,
'events': {
'onInsert': collection.collectionEvent.onInsert._listeners.length,
'onUpdate': collection.collectionEvent.onUpdate._listeners.length,
'onDelete': collection.collectionEvent.onDelete._listeners.length,
},
'indexes': await collection.collection.getIndexes(),
});
json[collection.name] = jsonCollection;
}
Console.json(json);
}