Dart DocumentationutilsTableDropper

TableDropper class

Drops a set of tables.

class TableDropper {
 ConnectionPool pool;
 List<String> tables;
 List<String> _tables = [];
 
 /**
  * Create a [TableDropper]. Needs a [pool] and
  * a list of [tables].
  */
 TableDropper(this.pool, this.tables);
 
 void _dropTables(Completer c) {
   afterDrop() {
     if (_tables.length == 0) {
       c.complete(null);
     } else {
       _dropTables(c);
     }
   }
   
   var table = _tables.removeAt(0);
   pool.query('drop table $table')
     // if it's an unknown table, ignore the error and continue
     .then((_) {
       afterDrop();
     })
     .catchError((e) {
       afterDrop();
     }, test: (e) => e is MySqlException && (e as MySqlException).errorNumber == ERROR_UNKNOWN_TABLE)
     .catchError((e) {
       c.completeError(e);
     });
 }

 /**
  * Drops the tables this [TableDropper] was created with. The 
  * returned [Future] completes when all the tables have been dropped.
  * If a table doesn't exist, it is ignored.
  * 
  * Do not run this a second time until the future has completed.
  */
 Future dropTables() {
   var c = new Completer();
   _tables.clear();
   _tables.addAll(tables);
   _dropTables(c);
   return c.future;
 }
}

Constructors

new TableDropper(ConnectionPool pool, List<String> tables) #

Create a TableDropper. Needs a pool and a list of tables.

TableDropper(this.pool, this.tables);

Properties

ConnectionPool pool #

ConnectionPool pool

List<String> tables #

List<String> tables

Methods

Future dropTables() #

Drops the tables this TableDropper was created with. The returned Future completes when all the tables have been dropped. If a table doesn't exist, it is ignored.

Do not run this a second time until the future has completed.

Future dropTables() {
 var c = new Completer();
 _tables.clear();
 _tables.addAll(tables);
 _dropTables(c);
 return c.future;
}