通过原生SQL判断数据是否存在
func (s *service) existMongodb(DBInstanceId string) (bool, error) { var DbInstanceDescription string err := s.db.QueryRow("SELECT db_instance_description FROM mongodb WHERE db_instance_id=?", DBInstanceId).Scan(&DbInstanceDescription) if err != nil { if err == sql.ErrNoRows { fmt.Println("no data") return false, nil } else { fmt.Printf("错误: %s", err) return false, err } } return true, nil }