0

In Go, how can I check if a AWS QLDB result is empty?

In node, the following would do the trick:

txn.execute(statement).then((result: Result) => {
  const resultList: dom.Value[] = result.getResultList();
  if (resultList.length === 0) {
     // DO something
  }
)}

I've been reading the official quick start, but examples "assumes the results are not empty":

p, err := driver.Execute(context.Background(), func(txn qldbdriver.Transaction) (interface{}, error) {
    result, err := txn.Execute("SELECT firstName, lastName, age FROM People WHERE age = 54")
    if err != nil {
        return nil, err
    }

    // Assume the result is not empty
    hasNext := result.Next(txn)
    if !hasNext && result.Err() != nil {
        return nil, result.Err()
    }

    ionBinary := result.GetCurrentData()

    temp := new(Person)
    err = ion.Unmarshal(ionBinary, temp)
    if err != nil {
        return nil, err
    }

    return *temp, nil
})
Vingtoft
  • 13,368
  • 23
  • 86
  • 135

0 Answers0