addIndex method

  1. @override
void addIndex(
  1. String name,
  2. List<String> columns,
  3. IndexType type
)

Implementation

@override
void addIndex(String name, List<String> columns, IndexType type) {
  // mask the column names, is more safety
  columns.map((column) => '"$column"');

  switch (type) {
    case IndexType.primaryKey:
      _stack.add(
        'ALTER TABLE "$tableName" ADD PRIMARY KEY (${columns.join(',')});',
      );
      break;
    case IndexType.unique:
      _stack.add(
        'CREATE UNIQUE INDEX IF NOT EXISTS "$name" '
        'ON "$tableName" (${columns.join(',')});',
      );
      break;
    case IndexType.standardIndex:
    case IndexType.none:
    default:
      _stack.add(
        'CREATE INDEX IF NOT EXISTS "$name" '
        'ON "$tableName" (${columns.join(',')});',
      );
      break;
  }
}