writeGeneratedSchema function
Future<void>
writeGeneratedSchema(
- String source, {
- String? output,
- SqlDialect? dialect,
- String? defaultNamespace,
Writes a typed client and Dart schema snapshot after validating source.
output defaults to the source basename with an .orm.dart extension.
The snapshot uses the corresponding .snapshot.dart basename. Both are
derived files and are replaced when generation succeeds. defaultNamespace
follows generateSchema's namespace resolution rules.
Implementation
Future<void> writeGeneratedSchema(
String source, {
String? output,
SqlDialect? dialect,
String? defaultNamespace,
}) async {
output ??= '${SchemaLayout.stem(source)}.orm.dart';
final result = await generateSchema(
source,
outputPath: output,
dialect: dialect,
defaultNamespace: defaultNamespace,
);
final file = File(output);
await file.parent.create(recursive: true);
final snapshot = result.snapshotDart;
await file.writeAsString(result.dart);
await File(_schemaSnapshotPath(output)).writeAsString(snapshot);
}