toSql method

String toSql({
  1. required String tableName,
  2. bool ifNotExists = false,
})

Implementation

String toSql({
  required String tableName,
  bool ifNotExists = false,
}) {
  // No need to log a warning here since unsupported indexes will be filtered
  // out by the migration manager.
  if (type != 'btree') {
    return '';
  }

  var uniqueStr = isUnique ? ' UNIQUE' : '';
  var elementStrs = elements.map((e) => '"${e.definition}"');
  var ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : '';

  return 'CREATE$uniqueStr INDEX$ifNotExistsStr "$indexName" ON "$tableName" '
      '(${elementStrs.join(', ')});\n';
}