I need to check if my query returns true or false. If it returns false, I want it to error out. Here is my code:
func (dr *dbrepo) checkIfUnique(datacenterstring) error {
statement := `select exists(select 1 from source where datacenter = $3)`
_, checkIfExists := dr.db.Query(statement)
if checkIfExists != nil {
log.Print("Error is not unique", checkIfExists)
return checkIfExists
}
return nil
}
The problem is: I think I need to convert checkIfExists
from a row to a bool and then see if it is true or false. But I am not sure on how to do that. Any ideas? Is there a better way to do this?