createTable method

List<String> createTable(
  1. SchemaTable table, {
  2. bool isTemporary = false,
})
inherited

Implementation

List<String> createTable(SchemaTable table, {bool isTemporary = false}) {
  final commands = <String>[];

  // Create table command
  final columnString = table.columns.map(_columnStringForColumn).join(",");
  commands.add(
    "CREATE${isTemporary ? " TEMPORARY " : " "}TABLE ${table.name} ($columnString)",
  );

  final indexCommands = table.columns
      .where(
        (col) => col.isIndexed! && !col.isPrimaryKey!,
      ) // primary keys are auto-indexed
      .map((col) => addIndexToColumn(table, col))
      .expand((commands) => commands);
  commands.addAll(indexCommands);

  commands.addAll(
    table.columns
        .where((sc) => sc.isForeignKey)
        .map((col) => _addConstraintsForColumn(table.name, col))
        .expand((commands) => commands),
  );

  if (table.uniqueColumnSet != null) {
    commands.addAll(addTableUniqueColumnSet(table));
  }

  return commands;
}