run static method

Future<void> run(
  1. List<String> args,
  2. SendPort port,
  3. GeneratedDatabase database(
    1. QueryExecutor
    )
)

Creates a SchemaExporter with the database, parses the single-argument args list as a dialect name, calls collectOnCreateStatements and sends the resulting list over the port.

This sequence is used by the drift_dev schema export command, which prints CREATE statements making up a drift database analyzed from source. For this to work, it emulates a drift build and then creates a Dart program calling this method.

This method is thus internal to that utility and likely not useful outside of that.

Implementation

static Future<void> run(
  List<String> args,
  SendPort port,
  GeneratedDatabase Function(QueryExecutor) database,
) async {
  final export = SchemaExporter(database);

  if (args case ['v2', final options]) {
    final parsedOptions = json.decode(options);
    final dialects = (parsedOptions['dialects'] as List).map(
      (e) => SqlDialect.values.byName(e as String),
    );

    final result = await export._collect(dialects: dialects);
    final serialized = [
      for (final row in result.collectedStatements)
        [row.element, row.dialect.name, row.stmt],
    ];

    port.send(serialized);
  } else {
    final statements = await export.collectOnCreateStatements(
      SqlDialect.values.byName(args.single),
    );
    port.send(statements);
  }
}