addCreateTableStatement method

void addCreateTableStatement(
  1. CreateTableStatement stmt
)

Implementation

void addCreateTableStatement(CreateTableStatement stmt) {
  statement.supportsVariables = false;
  final table = stmt.entity;

  if (table case final VirtualTableInfo virtual) {
    statement.buffer.write('CREATE VIRTUAL TABLE ');
    if (stmt.ifNotExists) {
      statement.buffer.write('IF NOT EXISTS ');
    }
    addReference(table.aliasOrName);
    statement.buffer.write(' USING ${virtual.moduleAndArgs}');
    return;
  }

  statement.buffer.write('CREATE TABLE ');
  if (stmt.ifNotExists) {
    statement.buffer.write('IF NOT EXISTS ');
  }
  addReference(table.aliasOrName);
  statement.buffer.write(' (');

  for (final (i, column) in table.columns.indexed) {
    if (i != 0) {
      statement.comma();
    }

    addTableColumnDefinition(column);
  }

  if (!table.dontWriteConstraints) {
    for (final constraint in table.constraints) {
      statement.comma();
      constraint.compileWith(this);
    }
  }

  for (final constraint in table.customConstraints) {
    statement
      ..comma()
      ..buffer.write(constraint);
  }

  statement.buffer.write(')');
  addTableModifiers(stmt);
  statement.buffer.write(';');
}