更新DynamoDB中的记录

时间:2019-05-14 14:26:49

标签: swift amazon-dynamodb

我将客户个人资料及其个人交易存储在DynamoDB中。我还创建了一个表来存储这些交易的汇总。 (示例:如果某个客户多次访问该市场,那么该表除了记录每个客户所花费的总金额的表外,还将有很多针对该客户的单独交易。)但是,在创建该表时,我不知道如何更新。

这是我用来进行单独的发行/交易的代码。

@IBAction func makeDistributionButtonPressed(_ sender: UIButton) {

        let distribution = Distribution(firstInitial: firstInitialTextField.text ?? "None", lastInitial: lastInitialTextField.text ?? "None", EBTCustomerNumber: EBTCustomerNumberTextField.text ?? "None", matchingMoneyAvailable: Int(availableMoneyForMatchingTextField.text!) ?? 0, amountCustomerRequests: Int(amountCustomerRequestTextField.text!) ?? 0, totalMatchDistributed: Int(matchMoneyOwedCustomerTextField.text!) ?? 0, totalEBTDistributed: Int(EBTOwedCustomerTextField.text!) ?? 0, totalOwedMarket: Int(amountOwedMarketTextField.text!) ?? 0, totalSpent: totalSpent)


            CreateDistribution().createDailyDistribution(input: distribution)

            self.updateAggregate()

        showMessage(messageToDisplay: "Distribution made!")

    }

这是我尝试用来执行更新的内容

func updateAggregate(){

        appSyncClient?.fetch(query: ListCustomerRegistrationsQuery(), cachePolicy: .returnCacheDataAndFetch) {(result, error) in
            if error != nil {
                print(error?.localizedDescription ?? "")
                return
            }
            result?.data?.listCustomerRegistrations?.items!.forEach {
                if $0?.firstInitial == self.firstInitialTextField.text?.uppercased() && $0?.lastInitial == self.lastInitialTextField.text?.uppercased() && $0?.needIndicatorId == self.EBTCustomerNumberTextField.text {
                    print(($0?.marketName)!)

                    let updateEBTTotal = Aggregate(firstInitial: self.firstInitialTextField.text ?? "None", lastInitial: self.lastInitialTextField.text ?? "None", EBTCustomerNumber: self.EBTOwedCustomerTextField.text ?? "None", totalMatchDistributed: Int(self.matchMoneyOwedCustomerTextField.text!) ?? 0, totalEBTDistributed: Int(self.EBTOwedCustomerTextField.text!) ?? 0)

                    CreateDistribution().updateAggregateTransactions(input: updateEBTTotal)

                }
                else{
                    print("Could not update the information.")
                }
            }
        }
    }

我正在尝试更新totalMatchDistributedtotalEBTDistributed字段。

0 个答案:

没有答案