generate method

String generate(
  1. LibraryReader library,
  2. List<SqliteFields> fieldses
)

Complete schema file output

classes are all classes by their table name with the @OfflineFirst annotation

Implementation

String generate(LibraryReader library, List<SqliteFields> fieldses) {
  final newSchema = _createNewSchema(library, fieldses);
  final existingMigrations = migrationGenerator.expandAllMigrations(library);

  final parts = existingMigrations.map((m) => "part '${m.version}.migration.dart';");
  final migrationClasses = existingMigrations.map((m) => 'const Migration${m.version}()');

  final output = """
    // GENERATED CODE DO NOT EDIT
    // This file should be version controlled
    import 'package:brick_sqlite/db.dart';
    ${parts.join("\n")}

    /// All intelligently-generated migrations from all `@Migratable` classes on disk
    final migrations = <Migration>{ ${migrationClasses.join(",\n")} };

    /// A consumable database structure including the latest generated migration.
    final schema = ${newSchema.forGenerator};
  """;
  return _formatter.format(output);
}