QueryRunner class
Runs a list of arbitrary queries. Currently only handles update queries as the results are ignored.
class QueryRunner {
final ConnectionPool pool;
final List<String> queries;
final List<String> _queries = [];
/**
* Create a [QueryRunner]. Needs a [pool] and
* a list of [queries].
*/
QueryRunner(this.pool, this.queries);
Future _executeQueries(Completer c) {
var query = _queries.removeAt(0);
pool.query(query).then((result) {
if (_queries.length == 0) {
c.complete(null);
} else {
_executeQueries(c);
}
})
.catchError((e) {
c.completeError(e);
});
}
/**
* Executes the queries this [QueryRunner] was created with. The
* returned [Future] completes when all the queries have been executed.
* Results are ignored.
*
* Do not run this a second time until the future has completed.
*/
Future executeQueries() {
var c = new Completer();
_queries.clear();
_queries.addAll(queries);
_executeQueries(c);
return c.future;
}
}
Constructors
new QueryRunner(ConnectionPool pool, List<String> queries) #
Create a QueryRunner. Needs a pool and a list of queries.
QueryRunner(this.pool, this.queries);
Properties
final ConnectionPool pool #
final ConnectionPool pool
Methods
Future executeQueries() #
Executes the queries this QueryRunner was created with. The returned Future completes when all the queries have been executed. Results are ignored.
Do not run this a second time until the future has completed.
Future executeQueries() {
var c = new Completer();
_queries.clear();
_queries.addAll(queries);
_executeQueries(c);
return c.future;
}