gotarantool

Running SQL queries in Tarantool from Go are silent (no errors)


I try to run SQL queries from a Golang application using the official Tarantool client. The only way I know how to do it is by using conn.Eval like below. But I don't receive any errors. I can drop non existing tables, insert rows with duplicate keys. I will never find out that something went wrong.

resp, err := conn.Eval("box.execute([[TRUNCATE TABLE not_exists;]])", []interface{}{})
// err is always nil
// resp.Error is always empty

Can you point out the way to get errors or the right way to run SQL queries.


Solution

  • thanks for the question!

    I have talked to the team and we have two options for you. Here is the first one:

      resp, err := conn.Eval("return box.execute([[TRUNCATE TABLE \"not_exists\";]])", []interface{}{})
          
      if len(resp.Tuples()) > 1 {
      fmt.Println("Error", resp.Tuples()[1])  
      }else{
      fmt.Println("Result", resp.Tuples()[0])  
      }
    

    And here is the second one:

     r, err := tnt.Eval("local data, err = box.execute(...) return data or box.error(err)", []interface{}{
      `TRUNCATE table "not_exists";`,
     })
     if err != nil {
      log.Fatalln(err)
     }
    

    I hope that helps! And if it doesn't - let me know and we will look into this one more time.