then<R> method

  1. @override
Future<R> then<R>(
  1. FutureOr<R> onValue(
    1. TetherClientReturn<TModel> value
    ), {
  2. Function? onError,
})
override

Main execution point - when the future is awaited

Implementation

@override
Future<R> then<R>(
  FutureOr<R> Function(TetherClientReturn<TModel> value) onValue, {
  Function? onError,
}) {
  Future<TetherClientReturn<TModel>> operation;

  switch (type) {
    case SqlOperationType.select:
      operation = _executeSelect();
      break;
    case SqlOperationType.insert:
      operation = _executeInsert().then((model) => model);
      break;
    case SqlOperationType.update:
      operation = _executeUpdate().then((model) => model);
      break;
    case SqlOperationType.delete:
      operation = _executeDelete().then(
        (_) => TetherClientReturn<TModel>(data: [], count: 0, error: null),
      );
      break;
    case SqlOperationType.upsert:
      operation = _executeUpsert().then((model) => model);
      break;
    default:
      throw UnsupportedError('Unsupported operation type: $type');
  }

  return operation.then(onValue, onError: onError);
}