According to the documentation, an N1QL query is executed in Go via gocb as follows:
myQuery := gocb.NewN1qlQuery("SELECT * FROM default")
rows, err := myBucket.ExecuteN1qlQuery(myQuery)
if err != nil {
fmt.Printf("N1QL query error: %s\n", err)
}
var row interface{}
for rows.Next(&row) {
fmt.Printf("Row: %+v\n", row)
}
if err := rows.Close(); err != nil {
fmt.Printf("N1QL query error: %s\n", err)
}
How can I access the cas value of each row (object) retrieved?
It would be great the get an answer here as I am facing the same issue.
As a workaround I just query for the id
Select meta().id from bucket where ...
and then I do a
result, err := bucket.DefaultCollection().Get(key, nil)
. From there I can access
result.Cas()
The other thing I tried was to add a property Cas to my entity and then changed the query to:
SELECT meta().cas, x.* from bucket x where ...
But the issue here is that when I save the entity, it gets a cas property inside the document and when I fetch it like I mentioned then it just fetches the value of that property instead of the actual cas value. I would really appreciate some guidance here.