createView method

Future<void> createView(
  1. ViewInfo<HasResultSet, dynamic> view
)

Executes a CREATE VIEW statement to create the view.

Implementation

Future<void> createView(ViewInfo view) async {
  final stmts = view.createViewStatements;
  if (stmts != null) {
    await _issueQueryByDialect(stmts);
  } else if (view.query != null) {
    final context =
        GenerationContext.fromDb(database, supportsVariables: false);
    final columnNames = view.$columns
        .map((e) => e.escapedNameFor(context.dialect))
        .join(', ');

    context.generatingForView = view.entityName;
    context.buffer.write('CREATE VIEW IF NOT EXISTS '
        '${context.identifier(view.entityName)} ($columnNames) AS ');
    view.query!.writeInto(context);
    await _issueCustomQuery(context.sql, const []);
  }
}