通过原生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
}

 

posted on 2021-09-18 09:46  裤裆内隐藏杀气  阅读(121)  评论(0编辑  收藏  举报

导航