Remove some usages of dynamic

This commit is contained in:
Simon Binder 2020-11-26 17:22:59 +01:00
parent 0259fd58fd
commit 87d6e2ad31
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
13 changed files with 73 additions and 67 deletions

View File

@ -1,5 +1,6 @@
## unreleased (breaking - 4.0)
- __Breaking__: Changed the `args` parameter in `QueryExecutor` methods to `List<Object?>`
- __Breaking__: Removed the second type parameter from `TypedResult.read`
- Support null safety
- Changed the sql representation of text types from `VARCHAR` to `TEXT`

View File

@ -182,7 +182,7 @@ class _VmDelegate extends DatabaseDelegate {
return Future.value();
}
Future _runWithArgs(String statement, List<dynamic> args) async {
Future _runWithArgs(String statement, List<Object?> args) async {
if (args.isEmpty) {
_db.execute(statement);
} else {
@ -193,24 +193,24 @@ class _VmDelegate extends DatabaseDelegate {
}
@override
Future<void> runCustom(String statement, List args) async {
Future<void> runCustom(String statement, List<Object?> args) async {
await _runWithArgs(statement, args);
}
@override
Future<int> runInsert(String statement, List args) async {
Future<int> runInsert(String statement, List<Object?> args) async {
await _runWithArgs(statement, args);
return _db.lastInsertRowId;
}
@override
Future<int> runUpdate(String statement, List args) async {
Future<int> runUpdate(String statement, List<Object?> args) async {
await _runWithArgs(statement, args);
return _db.getUpdatedRows();
}
@override
Future<QueryResult> runSelect(String statement, List args) async {
Future<QueryResult> runSelect(String statement, List<Object?> args) async {
final stmt = _db.prepare(statement);
final result = stmt.select(args);
stmt.dispose();

View File

@ -43,28 +43,28 @@ class _MultiExecutorImpl extends MultiExecutor {
}
@override
Future<void> runCustom(String statement, [List? args]) async {
Future<void> runCustom(String statement, [List<Object?>? args]) async {
await _writes.runCustom(statement, args);
}
@override
Future<int> runDelete(String statement, List args) async {
Future<int> runDelete(String statement, List<Object?> args) async {
return await _writes.runDelete(statement, args);
}
@override
Future<int> runInsert(String statement, List args) async {
Future<int> runInsert(String statement, List<Object?> args) async {
return await _writes.runInsert(statement, args);
}
@override
Future<List<Map<String, dynamic>>> runSelect(
String statement, List args) async {
Future<List<Map<String, Object?>>> runSelect(
String statement, List<Object?> args) async {
return await _reads.runSelect(statement, args);
}
@override
Future<int> runUpdate(String statement, List args) async {
Future<int> runUpdate(String statement, List<Object?> args) async {
return await _writes.runUpdate(statement, args);
}

View File

@ -23,23 +23,23 @@ abstract class QueryExecutor {
/// Runs a select statement with the given variables and returns the raw
/// results.
Future<List<Map<String, dynamic>>> runSelect(
String statement, List<dynamic> args);
Future<List<Map<String, Object?>>> runSelect(
String statement, List<Object?> args);
/// Runs an insert statement with the given variables. Returns the row id or
/// the auto_increment id of the inserted row.
Future<int> runInsert(String statement, List<dynamic> args);
Future<int> runInsert(String statement, List<Object?> args);
/// Runs an update statement with the given variables and returns how many
/// rows where affected.
Future<int> runUpdate(String statement, List<dynamic> args);
Future<int> runUpdate(String statement, List<Object?> args);
/// Runs an delete statement and returns how many rows where affected.
Future<int> runDelete(String statement, List<dynamic> args);
Future<int> runDelete(String statement, List<Object?> args);
/// Runs a custom SQL statement without any variables. The result of that
/// statement will be ignored.
Future<void> runCustom(String statement, [List<dynamic>? args]);
Future<void> runCustom(String statement, [List<Object?>? args]);
/// Prepares and runs [statements].
///
@ -119,7 +119,7 @@ class ArgumentsForBatchedStatement {
final int statementIndex;
/// Bound arguments for the referenced statement.
final List<dynamic> arguments;
final List<Object?> arguments;
/// Used internally by moor.
ArgumentsForBatchedStatement(this.statementIndex, this.arguments);

View File

@ -76,7 +76,7 @@ abstract class QueryDelegate {
///
/// If the statement can't be executed, an exception should be thrown. See
/// the class documentation of [DatabaseDelegate] on what types are supported.
Future<QueryResult> runSelect(String statement, List<dynamic> args);
Future<QueryResult> runSelect(String statement, List<Object?> args);
/// Prepares and executes the [statement] with the variables bound to [args].
/// The statement will either be an `UPDATE` or `DELETE` statement.
@ -84,7 +84,7 @@ abstract class QueryDelegate {
/// If the statement completes successfully, the amount of changed rows should
/// be returned, or `0` if no rows where updated. Should throw if the
/// statement can't be executed.
Future<int> runUpdate(String statement, List<dynamic> args);
Future<int> runUpdate(String statement, List<Object?> args);
/// Prepares and executes the [statement] with the variables bound to [args].
/// The statement will be an `INSERT` statement.
@ -92,11 +92,11 @@ abstract class QueryDelegate {
/// If the statement completes successfully, the insert id of the row can be
/// returned. If that information is not available, `null` can be returned.
/// The method should throw if the statement can't be executed.
Future<int> runInsert(String statement, List<dynamic> args);
Future<int> runInsert(String statement, List<Object?> args);
/// Runs a custom [statement] with the given [args]. Ignores all results, but
/// throws when the statement can't be executed.
Future<void> runCustom(String statement, List<dynamic> args);
Future<void> runCustom(String statement, List<Object?> args);
/// Runs multiple [statements] without having to prepare the same statement
/// multiple times.

View File

@ -26,15 +26,15 @@ mixin _ExecutorWithQueryDelegate on QueryExecutor {
}
}
void _log(String sql, List<dynamic> args) {
void _log(String sql, List<Object?> args) {
if (logStatements) {
print('Moor: Sent $sql with args $args');
}
}
@override
Future<List<Map<String, dynamic>>> runSelect(
String statement, List args) async {
Future<List<Map<String, Object?>>> runSelect(
String statement, List<Object?> args) async {
assert(_ensureOpenCalled);
final result = await _synchronized(() {
_log(statement, args);
@ -44,7 +44,7 @@ mixin _ExecutorWithQueryDelegate on QueryExecutor {
}
@override
Future<int> runUpdate(String statement, List args) {
Future<int> runUpdate(String statement, List<Object?> args) {
assert(_ensureOpenCalled);
return _synchronized(() {
_log(statement, args);
@ -53,7 +53,7 @@ mixin _ExecutorWithQueryDelegate on QueryExecutor {
}
@override
Future<int> runDelete(String statement, List args) {
Future<int> runDelete(String statement, List<Object?> args) {
assert(_ensureOpenCalled);
return _synchronized(() {
_log(statement, args);
@ -62,7 +62,7 @@ mixin _ExecutorWithQueryDelegate on QueryExecutor {
}
@override
Future<int> runInsert(String statement, List args) {
Future<int> runInsert(String statement, List<Object?> args) {
assert(_ensureOpenCalled);
return _synchronized(() {
_log(statement, args);
@ -71,7 +71,7 @@ mixin _ExecutorWithQueryDelegate on QueryExecutor {
}
@override
Future<void> runCustom(String statement, [List<dynamic>? args]) {
Future<void> runCustom(String statement, [List<Object?>? args]) {
assert(_ensureOpenCalled);
return _synchronized(() {
final resolvedArgs = args ?? const [];

View File

@ -5,7 +5,7 @@ class QueryResult {
/// The data returned by the select statement. Each list represents a row,
/// which has the data in the same order as [columnNames].
final List<List<dynamic>> rows;
final List<List<Object?>> rows;
final Map<String, int> _columnIndexes;

View File

@ -52,13 +52,14 @@ abstract class _BaseExecutor extends QueryExecutor {
.request(_ExecuteBatchedStatement(statements, _executorId));
}
Future<T> _runRequest<T>(_StatementMethod method, String sql, List? args) {
Future<T> _runRequest<T>(
_StatementMethod method, String sql, List<Object?>? args) {
return client._channel
.request<T>(_ExecuteQuery(method, sql, args ?? const [], _executorId));
}
@override
Future<void> runCustom(String statement, [List? args]) {
Future<void> runCustom(String statement, [List<Object?>? args]) {
return _runRequest(
_StatementMethod.custom,
statement,
@ -67,22 +68,23 @@ abstract class _BaseExecutor extends QueryExecutor {
}
@override
Future<int> runDelete(String statement, List args) {
Future<int> runDelete(String statement, List<Object?> args) {
return _runRequest(_StatementMethod.deleteOrUpdate, statement, args);
}
@override
Future<int> runUpdate(String statement, List args) {
Future<int> runUpdate(String statement, List<Object?> args) {
return _runRequest(_StatementMethod.deleteOrUpdate, statement, args);
}
@override
Future<int> runInsert(String statement, List args) {
Future<int> runInsert(String statement, List<Object?> args) {
return _runRequest(_StatementMethod.insert, statement, args);
}
@override
Future<List<Map<String, dynamic>>> runSelect(String statement, List args) {
Future<List<Map<String, Object?>>> runSelect(
String statement, List<Object?> args) {
return _runRequest(_StatementMethod.select, statement, args);
}
}

View File

@ -74,8 +74,8 @@ class _MoorServer {
return await executor.ensureOpen(_dbUser);
}
Future<dynamic> _runQuery(_StatementMethod method, String sql, List args,
int? transactionId) async {
Future<dynamic> _runQuery(_StatementMethod method, String sql,
List<Object?> args, int? transactionId) async {
final executor = await _loadExecutor(transactionId);
switch (method) {

View File

@ -51,23 +51,25 @@ class LazyDatabase extends QueryExecutor {
_delegate.runBatched(statements);
@override
Future<void> runCustom(String statement, [List? args]) =>
Future<void> runCustom(String statement, [List<Object?>? args]) =>
_delegate.runCustom(statement, args);
@override
Future<int> runDelete(String statement, List args) =>
Future<int> runDelete(String statement, List<Object?> args) =>
_delegate.runDelete(statement, args);
@override
Future<int> runInsert(String statement, List args) =>
Future<int> runInsert(String statement, List<Object?> args) =>
_delegate.runInsert(statement, args);
@override
Future<List<Map<String, dynamic>>> runSelect(String statement, List args) =>
_delegate.runSelect(statement, args);
Future<List<Map<String, Object?>>> runSelect(
String statement, List<Object?> args) {
return _delegate.runSelect(statement, args);
}
@override
Future<int> runUpdate(String statement, List args) =>
Future<int> runUpdate(String statement, List<Object?> args) =>
_delegate.runUpdate(statement, args);
@override

View File

@ -106,13 +106,13 @@ class _WebDelegate extends DatabaseDelegate {
}
@override
Future<void> runCustom(String statement, List args) {
Future<void> runCustom(String statement, List<Object?> args) {
_db.runWithArgs(statement, args);
return Future.value();
}
@override
Future<int> runInsert(String statement, List args) async {
Future<int> runInsert(String statement, List<Object?> args) async {
_db.runWithArgs(statement, args);
final insertId = _db.lastInsertId();
await _handlePotentialUpdate();
@ -120,7 +120,7 @@ class _WebDelegate extends DatabaseDelegate {
}
@override
Future<QueryResult> runSelect(String statement, List args) {
Future<QueryResult> runSelect(String statement, List<Object?> args) {
// todo at least for stream queries we should cache prepared statements.
final stmt = _db.prepare(statement)..executeWith(args);
@ -139,7 +139,7 @@ class _WebDelegate extends DatabaseDelegate {
}
@override
Future<int> runUpdate(String statement, List args) {
Future<int> runUpdate(String statement, List<Object?> args) {
_db.runWithArgs(statement, args);
return _handlePotentialUpdate();
}

View File

@ -21,20 +21,20 @@ class MockExecutorInternal extends _i1.Mock implements _i2.QueryExecutor {
_i4.Future<bool> ensureOpen(_i2.QueryExecutorUser? user) =>
super.noSuchMethod(
Invocation.method(#ensureOpen, [user]), Future.value(false));
_i4.Future<List<Map<String, dynamic>>> runSelect(
String? statement, List<dynamic>? args) =>
_i4.Future<List<Map<String, Object?>>> runSelect(
String? statement, List<Object?>? args) =>
super.noSuchMethod(Invocation.method(#runSelect, [statement, args]),
Future.value(<Map<String, dynamic>>[]));
_i4.Future<int> runInsert(String? statement, List<dynamic>? args) =>
Future.value(<Map<String, Object?>>[]));
_i4.Future<int> runInsert(String? statement, List<Object?>? args) =>
super.noSuchMethod(
Invocation.method(#runInsert, [statement, args]), Future.value(0));
_i4.Future<int> runUpdate(String? statement, List<dynamic>? args) =>
_i4.Future<int> runUpdate(String? statement, List<Object?>? args) =>
super.noSuchMethod(
Invocation.method(#runUpdate, [statement, args]), Future.value(0));
_i4.Future<int> runDelete(String? statement, List<dynamic>? args) =>
_i4.Future<int> runDelete(String? statement, List<Object?>? args) =>
super.noSuchMethod(
Invocation.method(#runDelete, [statement, args]), Future.value(0));
_i4.Future<void> runCustom(String? statement, [List<dynamic>? args]) =>
_i4.Future<void> runCustom(String? statement, [List<Object?>? args]) =>
super.noSuchMethod(
Invocation.method(#runCustom, [statement, args]), Future.value(null));
_i4.Future<void> runBatched(_i2.BatchedStatements? statements) =>
@ -62,20 +62,20 @@ class MockTransactionsInternal extends _i1.Mock
_i4.Future<bool> ensureOpen(_i2.QueryExecutorUser? user) =>
super.noSuchMethod(
Invocation.method(#ensureOpen, [user]), Future.value(false));
_i4.Future<List<Map<String, dynamic>>> runSelect(
String? statement, List<dynamic>? args) =>
_i4.Future<List<Map<String, Object?>>> runSelect(
String? statement, List<Object?>? args) =>
super.noSuchMethod(Invocation.method(#runSelect, [statement, args]),
Future.value(<Map<String, dynamic>>[]));
_i4.Future<int> runInsert(String? statement, List<dynamic>? args) =>
Future.value(<Map<String, Object?>>[]));
_i4.Future<int> runInsert(String? statement, List<Object?>? args) =>
super.noSuchMethod(
Invocation.method(#runInsert, [statement, args]), Future.value(0));
_i4.Future<int> runUpdate(String? statement, List<dynamic>? args) =>
_i4.Future<int> runUpdate(String? statement, List<Object?>? args) =>
super.noSuchMethod(
Invocation.method(#runUpdate, [statement, args]), Future.value(0));
_i4.Future<int> runDelete(String? statement, List<dynamic>? args) =>
_i4.Future<int> runDelete(String? statement, List<Object?>? args) =>
super.noSuchMethod(
Invocation.method(#runDelete, [statement, args]), Future.value(0));
_i4.Future<void> runCustom(String? statement, [List<dynamic>? args]) =>
_i4.Future<void> runCustom(String? statement, [List<Object?>? args]) =>
super.noSuchMethod(
Invocation.method(#runCustom, [statement, args]), Future.value(null));
_i4.Future<void> runBatched(_i2.BatchedStatements? statements) =>

View File

@ -19,27 +19,28 @@ class NullExecutor implements QueryExecutor {
}
@override
Future<void> runCustom(String statement, [List? args]) {
Future<void> runCustom(String statement, [List<Object?>? args]) {
throw UnsupportedError('runCustom');
}
@override
Future<int> runDelete(String statement, List args) {
Future<int> runDelete(String statement, List<Object?> args) {
throw UnsupportedError('runDelete');
}
@override
Future<int> runInsert(String statement, List args) {
Future<int> runInsert(String statement, List<Object?> args) {
throw UnsupportedError('runInsert');
}
@override
Future<List<Map<String, dynamic>>> runSelect(String statement, List args) {
Future<List<Map<String, Object?>>> runSelect(
String statement, List<Object?> args) {
throw UnsupportedError('runSelect');
}
@override
Future<int> runUpdate(String statement, List args) {
Future<int> runUpdate(String statement, List<Object?> args) {
throw UnsupportedError('runUpdate');
}